Displaying a different look for a post dependent on Category (2 posts)

  1. slowdive
    Posted 7 years ago #

    I like the category of each post to define how that post looks. A good example of this is on the ThinkProgress blog: http://thinkprogress.org/

    I've tried a couple things, such as:

    <?php if (is_category('postrock')) { ?>
    html to display
    <? } else { ?>
    html to display
    <? } ?>

    But that doesn't work. I assume because is_category is for IF we're on the category page for postrock, then display this.. not IF the category assigned to this post is post-rock, then display this.

    I've also tried:

    <?php if the_category() == postrock ?>

    But that only prints the category name.

    Any help is MAJORLY appreciated!

  2. Terry
    Posted 7 years ago #

    Sorry for the late reply, I was browsing through the forum and found your problem unresolved.

    You can use <?php in_category('ID') ?> or <?php in_category('category-slug') ?> to select the category you would want to :)

    For more information on how to use it, refer to this entry in the codex.

Topic Closed

This topic has been closed to new replies.

About this Topic