• Short of adding a large “If…ELSE” block to my header.php file, is there a more elegant way of displaying an alternate “header image” on different pages?

    Say I have 3 “Pages”. On Page one I want to use “Header-1.jpg”. Page two would you “Header-2.jpg” and so on. Page 3 has 2 sub pages that all should share “Header-3.jpg”.

    I have an all XHTML/CSS layout so in a static site thise would be super easy. I could add ‘class=header1’ to my “#Header” div. Since I am using WP I am trying to figure out how do this.

    I don’t want to setup completely different templates or stylesheets. I want to keep maintenance simple. I’d prefer not to have a huge IF…ELSE block of php if possible (especially since a few pages have sub-pages).

    The follow code does what I want to do but I’d rather find another way of doing this
    if ($_SERVER['REQUEST_URI'] == "/cms" || $_SERVER['REQUEST_URI'] == "/cms/") {
    header("Location: https://" . $_SERVER['HTTP_HOST'] . "/cms/home/"); /* Redirect browser */
    exit;
    }

    Using custom fields would be awesome but it looks like it won’t work as needed. I want to dynamically change a $headerBG in my header.php file depending on what page/section the user is in.

    Big thanks for any pointers in the right direction!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Do you want just the header to change or the styles, too? Do you want the header to be different on every page or just related to the page content? By category, page type, or Pages? There are a lot of questions we need answers to if you want a good answer.

    Here are some helpful resources that might have the answer you need in the meantime.

    Designing Headers
    Creating Multiple Single Posts for Different Categories
    The Loop in Action
    Conditional Tags

    Thread Starter pelias

    (@pelias)

    hi Lorelle — thanks for the reply. I will take a look at the links and hopefully I can answer your questions clearly.

    Ideally I would like a different header for each site section. Using WP’s “Page” functionality I have set up sections. Some sections have subpages to them. So to answer your question I want to be able to associate a header image to a top level “Page” (or any page if possible).

    For example I have the top level “Pages” — “Home” / “Services” / “About” / “Contact” — that break the site into 4 different sections. My goal is to be able to use a specified header image in each section. Additionally in sections with subpages the subpages will share the parents’ header. I.E. “Services” has 4 subpages that will share the “Services” section header.

    Being able to change the styles depending on the section would satisfy my needs. I could have my base styles static and section styles could be dynamic depending on the page.

    I do not employ categories for the pages but can if it will help.

    Thread Starter pelias

    (@pelias)

    I was able to make different “Pages” temlpates, added a php variable to the top of each template I needed (I.E. $headerBG = "header1"; and so on), as well as placed the variable in the “header.php” file where a css class would go:

    <div id="header" class="$headerBG">content</div>

    In the WP admin I just set each page to use the page template I want.

    This way I do not have worry about maintaining multiple headers/footers. I can change the design as needed while making the “pages” templates as portable as possible.

    Cool!

    I’m a relative Newbie to WordPress and PHP and was wondering if there was any chance someone could explain the process above a little more fully?

    I’m currently working on 2 sites which require different header (specific – not random) images for each page and am trying to figure out the most straight forward way of doing this without having unnecessary multiple page and header templates.

    Cheers.

    I finally found my answer – it seemed like whatever I tried it failed to call up a different header. Then I realised that instead of the standard get_header call in the page file I needed to use the:

    <?php include (TEMPLATEPATH . ‘/header1.php’); ?>

    call instead. It was actually in the wordpress documentation – in the Stepping Into Templates section…

    Think conditional tags would suit you better ?? https://theundersigned.net/2006/03/wordpress-conditional-tags/

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Displaying atlernate header.php content on different pages’ is closed to new replies.