WordPress.org

Ready to get started?Download WordPress

Forums

Problem With Conditional Tags (4 posts)

  1. Joe Hall
    Member
    Posted 6 years ago #

    Hey Folks,

    I am having a problem with conditional tags. I want a special message to appear above all of the post that are in category 12. Therefore I am using the following conditional tag

    <?php if(is_category('12')){echo 'This Is Category 12';}?>

    However, this tag only works on category templates and archive templates. It does not work on single post templates. Does anyone know why? And, does anyone know how I can display a special message on single posts that are in a certain category?

  2. DreDub38
    Member
    Posted 6 years ago #

    I am looking for the answer to this problem as well.

    What I am trying to do is say 'if this post is in category 13, then insert the contents of this php file'.

    Specifically, I want to insert an subscription link in the header of any post that is in my podcast category, no matter where the post shows up - main index, archive, single post, etc.

    I spent 2 hours looking on the forums, and another hour trying to figure it out using google. I apologize if I've missed the answer somewhere. Thanks in advance for any help you brainy folks can offer.

  3. BPartch
    Member
    Posted 6 years ago #

    Hello

    Try:

    <?php if(is_single() && in_category('12')){echo 'This Is a single post filed in Category 12';}?>

    Hope it helps. :)

  4. DreDub38
    Member
    Posted 6 years ago #

    BPartch, that absolutely helped me. I was able to modify it a little and it solved the single post part of my problem. (Thank You!)

    <?php if(is_single() && in_category('13')){include ('podcast-feed.php');}?>

    A little more fiddin' with it and I got it to work on my main index page as well

    <?php if(in_category('13')){include ('podcast-feed.php');}?>

    My problem was that I was trying to use is_category rather than in_category

    Thank you so much for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic