The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] if (in_category('')) is showing up on index too (6 posts)

  1. lowlight
    Posted 7 years ago #

    I am using

    if (in_category('19'))

    to display a line of text in the footer of posts that are only in that category.

    However, the footer is showing up on the index too!

    How can I remove that?

  2. MichaelH
    Posted 7 years ago #

    The in_category template tag can only be used in The Loop.

    Are you talking about displaying that in your footer when you display a single post with a Template such as single.php?

    Or are you talking about when you are displaying the posts in a given category such as a Category Archive?

  3. lowlight
    Posted 7 years ago #

    I put that in the footer.php, so it echos a string of text only to be shown at the bottom of single.php, only for posts that belong to category 19. It works for the most part, except index.php also displays it.

    Is there a better way to display a line of text in footer.php in single.php, only for certain categories?

  4. alanft
    Posted 7 years ago #

    you need is_single() && in_category('19')

    this is because in_category will evaluate true based on the (first or) last post in your loop. so adding the is_single condition will help

  5. lowlight
    Posted 7 years ago #

    Perfect, thanks

  6. taghaboy
    Posted 7 years ago #

    thanks a lot SIR alanft, you help me a lot,
    and this is my post :
    mybe it can help some one who search for global category.

Topic Closed

This topic has been closed to new replies.

About this Topic