• Resolved echstudios

    (@echstudios)


    I have 4 pages (About, Services, Portfolio, & Contact) that I want to have a different header image for each.

    I’ve set up the four styles in css (style1, style2, style3, style4) and I figure there must be a way to call each css image dynamically using PHP, from just the one header.php. Perhaps by Page ID?

    This is the current code in my header to call my image.
    <div id=”style”></div>

    Thanks in advance,
    Nick

Viewing 8 replies - 1 through 8 (of 8 total)
  • This might help: Conditional_Tags

    Thread Starter echstudios

    (@echstudios)

    To be honest, I’m just not sure how to implement that. Is there a way to simply specify which style number to access based on the Page ID?

    For example,
    Style1 for Page ID = 1
    Style2 for Page ID = 2
    etc

    and just implement some PHP in the div id?

    <div id=”style(PHP code to specify page ID)”></div>

    I hope I’m making sense.

    Thanks again.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    <div id="<?php
    if (is_page(1)) {
    echo 'style1';
    } else if (is_page(2)) {
    echo 'style2';
    } else if (is_page(3)) {
    ... and so on ...
    }
    ?>"> whatever </div>

    From here: https://css-tricks.com/new-screencast-current-nav-php-body-id/

    </head>
    
    <?php
    	$page = $_SERVER['REQUEST_URI'];
    	$page = str_replace("/","",$page);
    	$page = str_replace(".php","",$page);
    	$page = str_replace("?s=","",$page);
    	$page = $page ? $page : 'default'
    ?>
    
    <body id="<?php echo $page ?>">

    But adapt to style your header so:
    body#about #header { background:red; }

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Urgh! Yucky.

    If you want to do that, this works better:
    $pageid = get_query_var('page_id');

    Or if you want the slug, then you can continue on like so:

    $page = get_page($pageid);
    $slug = $page->post_name;

    Thread Starter echstudios

    (@echstudios)

    Thanks for the replies. I went with Otto’s first recommendation and it worked perfectly. Thanks a bunch.

    Thanks Otto, I also used your first suggestion and It worked perfectly right off the bat!

    planetrussell

    (@planetrussell)

    Folks, is there a WP plugin that will accomplish this? Custom PHP, CSS is fine, however a client wants the ability to do this for themselves via the Admin panel, as they add new categories. Any recommendations?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Header image based on Page ID?’ is closed to new replies.