WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] PHP: is_single for specific tagged single pages? (3 posts)

  1. derekbeck
    Member
    Posted 2 years ago #

    Anyone know how to construct an if/then statement for single pages that have a specific tag (or alternatively, a category)?

    I want to include a php file only on the display of certain posts based on their tag (or alternatively, category).

    Thanks!
    Derek

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    <?php if( in_category( '5' ) || has_tag( 'mild' ) ) :?>
    [ do stuff ]
    <?php endif;?>

    http://codex.wordpress.org/Conditional_Tag

  3. derekbeck
    Member
    Posted 2 years ago #

    Awesome, that worked great. FYI for future readers: the link above should be http://codex.wordpress.org/Conditional_Tags

    Also, I decided to go w/ category instead of tag, and here's the final code I used:

    if ( in_category(6) && is_single() ) {
    include("my.php");
    }

    I think the is_single is redundant with the in_category, as the latter probably must be on a single page, but this way I'm sure.

Topic Closed

This topic has been closed to new replies.

About this Topic