In my list of blog posts, I would like to show a div which labels the post as a “Press Release” if the post is tagged with the “Press” category.

I have added the following chunk into my loop:

<?php if (is_category( 'press' )) : ?><div class="category">Press Release</div><?php endif;?>

I have also tried replacing press with the category ID, but neither seem to work. Is this how I should be implementing this?

1 Answer
1

is_category() does this:

(…) Checks if a Category archive page is being displayed. (…)

One line below on the codex page you find:

To test if a post is in a category use in_category().

So just use the latter.

Leave a Reply

Your email address will not be published. Required fields are marked *