WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] different header.php files for different categories (4 posts)

  1. ellena_l
    Member
    Posted 6 years ago #

    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('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

  2. gmsand
    Member
    Posted 6 years ago #

    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.

  3. ellena_l
    Member
    Posted 6 years ago #

    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.

  4. ellena_l
    Member
    Posted 6 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic