• Hello. I’m trying to perform a check for a specific category in the single.php page for a single post. I can’t seem to get it to pick up the category properly. I’m attempting to do this with the following code:

    <?php if (is_category(‘6’) ): ?>
    This is a test
    <?php endif; ?>

    I’ve also tried swapping in the category name instead of the number. No matter what values I use, my text in the IF statement does not appear on the screen. I see some code on that page for displaying the category (“<?php the_category(”) ?>”), but that’s all it does. I need to actually use this in an “if” statement. Any ideas? Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You need to read the documentation before using Conditional_Tags.

    Thread Starter ozonshak

    (@ozonshak)

    Thank you for the information on the conditional tags. If I’m understanding this correctly, I probably can’t use the “is_category” method on the single.php page because I’m not actually on a category page, correct? If so, I’m still not clear how to solve my problem here. Can you give me any advice on how to do this? Thank you.

    My advice is: read more… EVERYTHING on a page that is given to you as a reference.

    in_category(‘5’)
    Returns true if the current post is in the specified category id. read more

    Note: Be sure to check your spelling when testing, “is” and “in” are a big difference.

    Thread Starter ozonshak

    (@ozonshak)

    Thanks! I think the advice should be read more carefully ?? I didn’t even see that small character difference on the first pass. I’ll give this a try. Thanks again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to check for specific category in single.php?’ is closed to new replies.