• I found this code at wordpress codex, my question is how do I use this code?

    <?php
    
    if ( is_page('about') || $post->post_parent == '2' ) {
        // the page is "About", or the parent of the page is "About"
        $bannerimg = 'about.jpg';
    
    } elseif ( is_page('learning') || $post->post_parent == '56' ) {
        $bannerimg = 'teaching.jpg';
    
    } elseif ( is_page('admissions') || $post->post_parent == '15' ) {
        $bannerimg = 'admissions.jpg';
    
    } else {
        $bannerimg = 'home.jpg'; // just in case we are at an unclassified page, perhaps the home page
    }	
    
    ?>

    How do I make it work with my <div>:

    <div id="image"><img src="BANNERHERE></div>

Viewing 1 replies (of 1 total)
  • Try this:

    <div id="image">
    <?php
    if ( is_page('about') || $post->post_parent == '2' ) {
        echo '<img src="aboutbanner">';
    
    } elseif ( is_page('learning') || $post->post_parent == '56' ) {
        echo '<img src="learningbanner">';
    
    } elseif ( is_page('admissions') || $post->post_parent == '15' ) {
        echo '<img src="admissionbanner">';
    
    } else {
        echo '<img src="banner">';
    }	
    
    ?>
    </div>

Viewing 1 replies (of 1 total)
  • The topic ‘Conditional Tags’ is closed to new replies.