Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a defined set of seven different post types and would like to display an icon for each one in the search results list.

I've got the following code to display the post type but have no idea how to extend it into an if

<?php $post_type = get_post_type_object( get_post_type($post) );
echo $post_type->label ; ?>

Any help appreciated.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted
<?php 
   $post_type = get_post_type($post);
   switch ($post_type) {
       case "type1":
           echo "<img src='label1.png'/>";
           break;
       case "type2":
           echo "<img src='label2.png'/>";
           break;
   }
?>
share|improve this answer
    
You can also access the post type directly from the $post object: $post->post_type. –  Geert Dec 5 '11 at 12:27
add comment

You could also do this with CSS. If you're using post_class() in the search results it will have the post-type available within each post's classes for styling each type differently.

Then you just apply a different background image as an icon for each post type class.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.