Conditional sidebars according to category and children
-
Hello
For single post I want to create a conditional to bring in certain sidebars according to the categroy that the post is in.
For example I would like to call in the sidebar_music.php when the post is in either music or a subcategory (child) of music. Music is a section or category of my site and is assigned cat ID 5
Thus the music sidebar would appear in both these cases
https://mysite.com/music/article
https://mysite.com/music/concerts/articleI assume the code would look something like this. I am a novice with PHP so I don’t know the correct syntax but the perintent functions and logic are basically here. My main problem is I do not know how to define the category and ALSO the children of that category within this conditional.
<?php
if(is_category(‘5&&child_of=5’))
include (‘music_sidebar.php’);
elseif (is_category(9&&child_of=9))
include (‘tv_sidebar.php’);
elseif (is_category(8&&child_of=8))
include (‘dining_sidebar.php’);
?>
- The topic ‘Conditional sidebars according to category and children’ is closed to new replies.