Support » Fixing WordPress » if (in_category(”)) is showing up on index too

  • Resolved lowlight


    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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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?

    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?

    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

    Perfect, thanks

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘if (in_category(”)) is showing up on index too’ is closed to new replies.