WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. lowlight
    Member
    Posted 5 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
    Member
    Posted 5 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
    Member
    Posted 5 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
    Member
    Posted 5 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
    Member
    Posted 5 years ago #

    Perfect, thanks

  6. taghaboy
    Member
    Posted 5 years ago #

    thanks a lot SIR alanft, you help me a lot,
    and this is my post :
    http://wordpress.org/support/topic/259606?replies=8
    mybe it can help some one who search for global category.
    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic