alchymyth on "category elseif statement"
March 2, 2010 by David Olsen
ok – the page you pointed me to is actually not a category page, it is an archive page – so no wonder that the if(is_category()) did not work.
try to use if(in_category()) instead (in archive.php):
<?php if(in_category('4')) { echo 'Deals'; }
if(in_category('3')) { echo 'Living'; }
if(in_category('26')) { echo 'deals!'; }
if(in_category('22')) { echo 'Events'; }
if(!in_category('4') && !in_category('3') && !in_category('26') && !in_category('22')) { echo 'Blog'; }
?>
hope this works smoothly, assuming the articles have only one of the categories, and there is only one article showing.
(actually, you can see that you have done things right so far, if you click on the small ‘events’ at the bottom of the post, where it says ‘filed under Events’ – that will direct you to the category.php – and it will show ‘events’ on the top. you are now going to get it working for archive.php)





Comments
Facebook comments:
Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!