I have two categories for my posts, "event" and "long-term-leasing." I have sidebar-events.php and sidebar-long-term.php. I wrote a conditional statement in single.php, but when I view a post it only shows me the generic sidebar. I did a copy/paste of the categories to avoid typos. Where is my mistake?
<?php
if (is_category("event")) {
get_sidebar('events');
} elseif (is_category('long-term-leasing')) {
get_sidebar('long-term');
} else {
get_sidebar();
}
?>
I have two categories for my posts, "event" and "long-term-leasing." I have sidebar-events.php and sidebar-long-term.php. I wrote a conditional statement in single.php, but when I view a post it only shows me the generic sidebar. I did a copy/paste of the categories to avoid typos. Where is my mistake?
<?php
if (is_category("event")) {
get_sidebar('events');
} elseif (is_category('long-term-leasing')) {
get_sidebar('long-term');
} else {
get_sidebar();
}
?>
Try has_category
, instead; is_category
is used for archive pages, not single posts.
For all who are struggling, here is what worked for me:
<?php
if (in_category("event")) {
get_sidebar('events');
} elseif (in_category('long-term-leasing')) {
get_sidebar('long-term');
} else {
get_sidebar();
}
?>
wp_reset_query();
before theif
block starts. – Sally CJ Commented Dec 23, 2018 at 0:14single.php
". That's why theis_category()
fails. Tryin_category()
. But I assume the post would only be in one of those categories? – Sally CJ Commented Dec 23, 2018 at 5:11