Multpi-category conflict: how to use in_category when >1 category exists?
-
Problem: I need to show different post content depending on the category being viewed (all posts all in multiple categories).
Possible solution: Custom fields would be easy except it’s long paragraph text that needs formatting. (can custom fields be formatted (easily by non WP people))?
Example
postname = I’m Not That Smart
post slug = im-not-that-smart
post is in 3 categories = category A, B & CSo I need to ……
if viewing at URL/category-a/im-not-that-smart, then show ‘content 1’
else if viewing at URL/category-b/im-not-that-smart, then show ‘content 2’
else if viewing at URL/category-c/im-not-that-smart, then show ‘content 3’Any ideas?
I’ve installed the Secondary Content plugin which is excellent (https://www.cmurrayconsulting.com/software/wordpress-secondary-html-content)
and this works perfectly via if in_category when each post is in one category ONLY, using this method …..
‘<?php the_content(); ?>
<?php the_secondary_content(); ?>
<?php if(post_is_in_descendant_category(4)) : ?><?php the_secondary_content(2); ?><?php endif;?>
<?php if(post_is_in_descendant_category(5)) : ?><?php the_secondary_content(3); ?><?php endif;?>
<?php if(post_is_in_descendant_category(6)) : ?><?php the_secondary_content(4); ?><?php endif;?>
‘
But obviously when the post belongs in all categories, each in_category is true, and all secondary_contents are shown.Is it possible to call/detect the category which the post is being viewed in? Can you call the category slug or something?
- The topic ‘Multpi-category conflict: how to use in_category when >1 category exists?’ is closed to new replies.