I have multiple categories let's call them Group1 (imp1, imp2, imp3) and group2 (cat1, cat2, cat3, cat4).

My posts are in one from the first group of categories and in multiple categories from the second group.

I want to show a small icon in the corner of the post thumbnail if the post is from imp1, or show another icon if the post is from imp2 and so on.


Add post_class() to the post container div:

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <!-- post markup here -->

...which will give you, among other classes:

  • .category-{ID}
  • .category-{slug}

You can then target those classes via CSS to add category-specific icons.

  • Can you please give me more details? – Desolator Nov 26 '13 at 21:02
  • What more (WordPress-specific) details do you need? – Chip Bennett Nov 26 '13 at 21:08
  • Can you show me how to do that with this code: <?php if( get_post_meta($post->ID, "thumb", true) ): ?> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php echo ($thumb); ?><?php $values = get_post_custom_values("thumb"); echo $values[0]; ?>" width="156" height="132" alt="<?php the_title(); ?>"></a> – Desolator Nov 26 '13 at 21:19
  • Sure. Just put that code where I have <!-- post markup here -->. – Chip Bennett Nov 26 '13 at 21:47
  • 1
    or I could use <?php if( in_category('SMS') ) { echo "This is something";} ?> – Desolator Nov 26 '13 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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