WordPress.org

Ready to get started?Download WordPress

Forums

Conditional Tags (2 posts)

  1. rize
    Member
    Posted 3 years ago #

    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>

  2. 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>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.