WordPress.org

Ready to get started?Download WordPress

Forums

single post show message according to category tht post is in (5 posts)

  1. oldbag66
    Member
    Posted 5 years ago #

    In single.php i need to have some conditionals that ask what category the post is in so i can display a message, not sure how to do this, but this is the idea:

    if post in category '2' say "hello dude
    elseif in category '3' say "proper bo"
    or else "nothing to say"

  2. MichaelH
    Member
    Posted 5 years ago #

    This would need to be in The Loop in your template:

    <?php
    $message='';
    if (in_category('2') ) {
    $message='hello dude';
    } elseif ( in_category('3') ) {
    $message='proper bo';
    } else {
    $message = 'nothing to say';
    }
    echo $message;
    ?>
  3. oldbag66
    Member
    Posted 5 years ago #

    ah sorry i should have said its to run outside of the loop, can i run a separate loop to deal with this?

  4. MichaelH
    Member
    Posted 5 years ago #

    Don't be confused by The Loop. Even single post templates (e.g. single.php) have a loop--even to display just one post.

  5. frescova
    Member
    Posted 4 years ago #

    Exactly what I needed!
    thanks :-)

Topic Closed

This topic has been closed to new replies.

About this Topic