Support » Themes and Templates » Not sure how to use the in_category if statement

  • Patrick

    (@randomgift)



    I’d like to show some text and PHP only if a a post belongs to a specific category, using the single.php.

    I’m not sure how to format this, any advice?

    Thanks a lot

Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael

    (@alchymyth)

    <?php if( in_category('specific') ) :
    /*php here for 'specific' posts*/
    else :
    /*php for other*/
    endif; ?>

    http://codex.wordpress.org/Function_Reference/in_category

    if you need to switch between html and css, make sure to close/open the php tags accordingly

    Patrick

    (@randomgift)

    Thanks very much, sucha big help.

    What about plain old <p>paragraphs</p>, do I neet to include anything different?

    Cheers again.

    Michael

    (@alchymyth)

    the old <p> tags are html code; therefore close the php tag before inserting the html paragraphs, then open the php tags again before any php code section;

    example:

    <?php if( in_category('specific') ) :
    /*php here for 'specific' posts*/ ?>
    <p>paragraphs</p><!-- this is a html section -->
    <?php else :
    /*php for other*/
    endif; ?>

    Patrick

    (@randomgift)

    Superstar, thank you again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Not sure how to use the in_category if statement’ is closed to new replies.