Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a static top banner on my website build like this :

<div class="row-fluid top-banner">
        <div class="container">
            <div class="banner-overlay"></div>
            <?php 
            $logo = of_get_option('logo', '' );
            if ( !empty( $logo ) ) { ?>
                <a class="brand brand-image" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><img src="<?php echo $logo; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"><h1><?php if(!of_get_option('disable_description')){ ?><small><?php bloginfo( 'description' ); ?></small><?php } ?></h1></a>
            <?php }else{ ?>
                <a class="brand brand-text" href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><h1><?php bloginfo( 'name' ); ?><?php if(!of_get_option('disable_description')){ ?><small><?php bloginfo( 'description' ); ?></small><?php } ?></h1></a>
            <?php } 
            if(of_get_option('disable_description')){ $top_banner_fix = 'style="top:15px;"'; }else{ $top_banner_fix = ''; }
            ?>

        </div>
    </div>

Now, I've created a "Contact Us" page and here I want to have other content inside the top banner.

What is the simplest solution for achieving this?

Do I need to create a page template for this ? Thanks!

share|improve this question
    
How are your templates structured in relation to that snippet and template used for pages? –  Rarst Sep 17 '13 at 12:42
    
Templates are standard is just a blog layout with small modifications –  agis Sep 18 '13 at 9:51
    
This snippet is in the header.php file –  agis Sep 18 '13 at 10:07

1 Answer 1

up vote 1 down vote accepted

The simplest way is to use conditional tags is_page(),

For example

<div class="row-fluid top-banner">
<div class="container">
    <div class="banner-overlay"></div>
    <?php 
    $logo = of_get_option('logo', '' );
    if ( !empty( $logo ) ) { ?>
        if ( is_page( 'contact' ) ) {
            <a class="brand brand-image" href="<?php echo esc_url( home_url( '/contact/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="contact"><img src="<?php echo $newsource; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"><h1><?php if(!of_get_option('disable_description')){ ?><small><?php bloginfo( 'description' ); ?></small><?php } ?></h1></a>
        } else {
            <a class="brand brand-image" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><img src="<?php echo $logo; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"><h1><?php if(!of_get_option('disable_description')){ ?><small><?php bloginfo( 'description' ); ?></small><?php } ?></h1></a>
        }
    <?php }else{ ?>
        <a class="brand brand-text" href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><h1><?php bloginfo( 'name' ); ?><?php if(!of_get_option('disable_description')){ ?><small><?php bloginfo( 'description' ); ?></small><?php } ?></h1></a>
    <?php } 
    if(of_get_option('disable_description')){ $top_banner_fix = 'style="top:15px;"'; }else{ $top_banner_fix = ''; }
    ?>

</div>

In the conditional tag is_page( 'contact' ) you can see i have added a new image source which would show a new image in the contact page.

You can also use ids, slugs of the page and also can pass an array.

http://codex.wordpress.org/Function_Reference/is_page

Hope it helps!

share|improve this answer
2  
+1 but please show an example and how he should use that function. Also please use the editor to format links. –  kaiser Sep 17 '13 at 13:43
    
I would like to see an example in this case, how can I use that conditional to change the top banner div content ? –  agis Sep 18 '13 at 9:50
    
Added an example... hope it helps –  Maruti Mohanty Sep 18 '13 at 11:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.