• i just can not get this to work at all!

    [please remember to mark your code using the ‘code’ button]

    <?php if (in_category('76')) { ?>
    - Manchester Utd -
    
    <?php } elseif (in_category('92')) { ?>
    - West Ham Utd -
    
    <?php } else { ?>
    <p>This is some generic text to describe all other category pages,
    I could be left blank</p>
    <?php } ?>

    It will always show – Manchester Utd – in the west ham category and im jsut not sure why.

    Im trying to change the logo in the header.php file per category so that it shows for parent category and all sub posts.

    help appreciated

Viewing 3 replies - 1 through 3 (of 3 total)
  • in_category() makes the most sense in single.php;

    if used in index.php outside the loop, it might be influenced only by the last post in the list.
    to avoid this confusion, you may neede to combine the conditional with is_single()

    a link yo your site (or a description where you are using these conditionals) might help to illustrate the problem.

    Thread Starter dannyblank

    (@dannyblank)

    Thanks ofr that but the site is in dev so i cant really share it at the moment as it is a client project!

    I am trying to achieve a different logo for each category and its corresponding posts under it.

    So Manchester Utd Category would display some kind of manchester united logo in the header! Etc Etc…..

    I can get the logo to show using the if (is_category) condition but that same logo will not remain for the categories posts.

    Thread Starter dannyblank

    (@dannyblank)

    Ive fixed it!

    As im setting the site up i had one post assigned to multiple categories.

    This was causing the logo image to inherit from the last listed category.

    I can confirm the working code is

    <?php if (in_category('manchester-united')) { ?>
    <p>This is the Manchester United category</p>
    
    <?php } elseif (in_category('norwich-city')) { ?>
    <p>This is the Norwich City category</p>
    
    <?php } elseif (in_category('england')) { ?>
    <p>This is the England category</p>
    
    <?php } else { ?>
    <p>This is some generic text to describe all other category pages,
    I could be left blank</p>
    <?php } ?>

    Hope this help anybody that hasnt found a workaround!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘If in Category issues’ is closed to new replies.