Hi, Im looking for a way to check the category and display a thumbnail based on the category. (this will be on the main page). The code i have so far just pulls in an image if no thumbnail is set. See below. Can anyone suggest a way to help me change it to select an image based on categories. e.g - If category has tumbnail, display it. Else If category is Sheep - Display sheep.jpg. Thanks. <?php $thumb = get_post_meta($post->ID, 'Image', true); if ($thumb == '') { ?> <a href="<?php the_permalink() ?>"> <img src="http://www.mysite.com/images/standard.jpg" alt="<?php the_title(); ?>" class="left" width="150px" height="150px"/> </a> <?php } ?> Code (markup):
if (in_category('2')){ //Display thumbnail for cat 2 } else if(in_category('5')){ //Display thumbnail for cat 5 } PHP: and change cat numbers as required
Like wd_2k6 said, that should do it. However if you have more categories, you should simply try a different method, like maybe adding a new custom field thumb_type or something, so you won't have to get to a lot of ifs and elses. Good luck