wordpress - how to load custom single.php? -
Hello I have a blog where class news, events and inspiration are there. These categories are selected using the radio buttons on ACF. I want to load news on the news alone. PPP while single-event. Program on FPP and motivation alone. Inspiration on PPP
Doing this Is it possible to use ACF field? To load custom code I have come to this code with the default categories of WordPress
$ post = $ wp_query- & gt; Post; If (in_category ('1')) {included (templat. '/ Single 1.php'); } Otherwise (in_category ('2')) {Include (templatepot '/ single2.php'); } Other {Include (temp. '/ Single_default.php'); } What can be used? While using ACF?
Thanks guys.
You can do acf_category to handle your ACF field .. < / p> $ post = $ wp_query- & gt; Post; $ post_cat = get_field ('acf_category', $ post-> ID); Switch ($ post_cat) {Case "News": Include (templatepart. '/ Single-news.fp'); break; Case "events" include: (templatepath. '/ Single-events.php'); break; The case "motivation" includes: (templight. '/ Solo-inspection.fp'); break; Default: Include (templatepath. '/ Single.php'); } Note that you may have to change the switch cases (this can also be done with if / else ) To reflect the actual slag of your ACF, this is just an important part of the important part of the get_field () function call, which will pull the appropriate FF field for the Post ID. There is a list of all ACF functions, very well documented
Comments
Post a Comment