• Resolved ellena_l

    (@ellena_l)


    Hi everyone,
    have a question how to implement different headers for different categories?
    Right now I have the following (I have created 4 php files for headers and added this lines to the archives.php, single.php, index.php):
    <?php
    if (in_category(‘hopes’)) {
    include (‘header-hopes.php’);
    }
    elseif (in_category(‘memories’)) {
    include (‘header-memories.php’);
    }
    elseif (in_category(‘dreams’)) {
    include (‘header-dreams.php’);
    }
    else {
    include (‘header.php’);
    }
    ?>
    but this doesn’t work, I have only header.php included everywhere. Have no clue why as I’m not good in php.
    I need only this 3 to be different. The function is_category or the method of creating special category-6 or sth do not work as I need EVERYTHING that is assigned to the category (including single posts and lots of subcategories in it) to have a certain header and style.css that is written there.

    Any ideas how to do this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You are supposed to use category IDs, not names.
    https://codex.www.ads-software.com/Template_Tags/in_category

    Thread Starter ellena_l

    (@ellena_l)

    Hi haochi
    I used both – category ids and category slugs. Both don’t work.

    Thread Starter ellena_l

    (@ellena_l)

    I noticed strange thing, it depends on the order:
    – so if I put memories at the first position only this header is used for all
    – if I put dreams as the first and memories as the last, memories works for memories and dreams works for dreams and hopes
    – if I put hopes as the first and memories as the last, memories works for memories and hopes works for dreams and hopes
    so everything that goes at the first position is used for everything except memories

    Thread Starter ellena_l

    (@ellena_l)

    I found out what the problem was. If I have one post assigned to two of this categories, then it doesn’t work. I removed the post from one category and now it works fine.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘different header.php files for different categories’ is closed to new replies.