Top

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)

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • NewsVine
  • Reddit
  • StumbleUpon
  • Google Bookmarks
  • Yahoo! Buzz
  • Twitter
  • Technorati
  • Live
  • LinkedIn
  • MySpace
  • Share/Bookmark

Related posts:

  1. thinkinginvain on "Help with Blog Post" Your blog page is drawing from the index.php file in...
  2. HAMMADHASSAN on "New Category Templates in WordPress 2.9" Until now you had to use a query in your...
  3. antr on "assign a template to all the post in a category" Which is the simplest way to assign the same template...
  4. alchymyth on "add comments to more pages" do you mean you want to add a comment option...
  5. jumptojump2001 on "auto show array entry?" <?php $cateArray = null;?> <?php while (have_posts()) : the_post(); ?>...

Related posts brought to you by Yet Another Related Posts Plugin.

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!





Security Code:

Bottom