Support » Themes and Templates » different header.php files for different categories

  • Resolved 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):
    if (in_category(‘3’)) {
    include (‘header-hopes.php’);
    elseif (in_category(‘2’)) {
    include (‘header-memories.php’);
    elseif (in_category(‘4’)) {
    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-2 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?

    PS. I noticed strange thing in my code, 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 all except memories

Viewing 3 replies - 1 through 3 (of 3 total)
  • Have you considered using rotating headers? I use five different header images that change with each click on a new link. I know it’s not ‘exactly’ what you’re looking for but it works. Check it out here.

    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.

    thank you, gmsand, but that is not what I need

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