Conditional tags: show image if post is in category X

Here we will discuss about the wordpress general help and support.
  • Ads

Conditional tags: show image if post is in category X

Postby albert » Wed Aug 04, 2010 11:56 pm

I want to add a specific image to my posts, depending on which category the post is in. I've added this to single.php:

<?php if (in_category('stamppotje')) { ?>
<img src="http://kokenvoormijndochter.nl/wp-content/themes/twentyten-koken/images/s.png">

<?php } elseif (in_category('smoothie')) { ?>
<img src="http://kokenvoormijndochter.nl/wp-content/themes/twentyten-koken/images/m.png">

<?php } else { ?>
<img src="http://kokenvoormijndochter.nl/wp-content/themes/twentyten-koken/images/v.png">

<?php } ?>

That works fine: a little image is displayed below the title, as you can see here for example (site is in dutch but that shouldn't matter ;-)

Now I want to do the same on the blog's main page, adding the same little image below the titles of posts displayed, depending on their category. I've tried adding the same code to loop.php, but there it doesn't work. I can't understand why not. Help would be much appreciated!
albert
Jr. Member
Jr. Member
 
Posts: 120
Joined: Mon Jul 26, 2010 1:40 am

Re: Conditional tags: show image if post is in category X

Postby albert » Wed Aug 04, 2010 11:56 pm

Argh it does work, I just posted it in the wrong part of loop.php.

Never mind :)
albert
Jr. Member
Jr. Member
 
Posts: 120
Joined: Mon Jul 26, 2010 1:40 am

Re: Conditional tags: show image if post is in category X

Postby sundar » Wed Aug 04, 2010 11:57 pm

Nice blog. Made me hungry.
sundar
Newbie
Newbie
 
Posts: 87
Joined: Mon Jul 26, 2010 1:48 am

  • Ads

Return to Wordpress General Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron