Forums

code to show if post is in X category (4 posts)

  1. josiahstaggs
    Member
    Posted 3 years ago #

    I've figured out how to make something show up on the sidebat if your viewing a certain category but now i want to extend that by have that same something show up if a particular post is within that category as well.

    Here my code so far:

    <?php if (is_category('18')) { ?>
    
    main stuff. need to also include on sidebar for posts in this category too.
    
    <?php } elseif (is_category('Category 56')) { ?>
    
    stuff
    <?php } else { ?>
    
    stuff
    <?php } ?>
  2. stvwlf
    Member
    Posted 3 years ago #

  3. josiahstaggs
    Member
    Posted 3 years ago #

    Thank you for the link I played around with the "||" and "!" but i can't figure out the proper code.

  4. t31os
    Member
    Posted 3 years ago #

    if(in_category(1)) {
    do stuff
    } elseif(in_category(2)) {
    do other stuff
    } else {
    do something else
    }

    Without quotes on the cat ID i think...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags