WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display SubHeader if in Certain Category (4 posts)

  1. kennethwatt
    Member
    Posted 5 years ago #

    Hi guys
    I have the following code in a post. I want to have it so that there is the header (which contains the links to Technology and Entertainment).
    If the post is in Technology, I wish for there to be a subheader which contains a list of all sub categorys in Technology, and similarly in Entertainment.)
    I have the following code:

    <?php if (is_category('Technology')) { ?>
    <div id="subheader">This is the technology sub header.</div>
    <?php } elseif (is_category('Entertainment')) { ?>
    <div id="subheader">This is the entertainment sub header.</div>
    <?php } else { ?>
    <div id="subheader">This post aint got no category.</div>
    <?php } ?>

    In a post in the Entertainment category just shows "this post ain't got no category", which is the else one, as does a post in Technology. It doesn't change if the post is ONLY in Technology and in no other one.

    Many thanks

    Kenneth Watt

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    is_category('foo') tests to see if the current display is the archive page for the Category 'foo'. To test whether the currently displayed post is in a given category, use in_category.

  3. kennethwatt
    Member
    Posted 5 years ago #

    Cheers that's great :)

  4. kennethwatt
    Member
    Posted 5 years ago #

    What should I use for if in BOTH?
    Thanks in advance

Topic Closed

This topic has been closed to new replies.

About this Topic