WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 1 down vote accepted
   $post_type = get_post_type($post);
   switch ($post_type) {
       case "type1":
           echo "<img src='label1.png'/>";
       case "type2":
           echo "<img src='label2.png'/>";
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

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

Your Answer


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.