• Resolved orbitor

    (@orbitor)


    I’m trying to display a different header on each separate page on my site using this code:

    <?php if (is_page(about)) { ?>
    <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2009/03/homepage2.jpg" />
    
    <?php } else if (is_page(programs)) { ?>
    <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2009/03/homepage2.jpg">
    
    <?php } else if (is_page(calendar)) { ?>
    <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2009/03/calendar.jpg">
    
    <?php } else if (is_page(donate)) { ?>
    <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2009/03/donate.jpg">
    
    <?php } else if (is_page(endangered-treasures)) { ?>
    <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2009/03/endangered.jpg">
    
    <?php } else if (is_page(scholarships-grants)) { ?>
    <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2009/03/scholarships.jpg">
    
    <?php } else if (is_page(sustainable-purchasing)) { ?>
    <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2009/03/sustainable.jpg">
    
    <?php } else if (is_page(forum)) { ?>
    <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2009/03/sustainable.jpg">
    
    <?php } else { ?>
    <img src="<?php bloginfo('url'); ?>/wp-content/uploads/2009/03/homepage2.jpg">

    There are two problems. First of all, it seems to ignore the final else statement and instead shows endangered.jpg. Second, it seems to ignore child pages. scholarships-grants for example is a child page (parent programs).

Viewing 2 replies - 1 through 2 (of 2 total)
  • Your php code contains errors. Try this general format (with added elseif) instead:

    <?php if (is_page('about')) { ?>
    <!-- code here -->
    
    <?php } elseif (is_page('programs')) { ?>
    <!-- code here -->
    
    <?php } elseif (is_page('calendar')) { ?>
    <!-- code here -->
    
    <?php } else { ?>
    <!-- code here -->
    
    <?php } ?>

    Also, your image tags are not closed. All tags, even single tags must be closed with XHTML (what WordPress uses).

    https://codex.www.ads-software.com/HTML_to_XHTML

    Thread Starter orbitor

    (@orbitor)

    Thank you iridiax! I just found the same errors about 20 later than you ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘php else if for child pages’ is closed to new replies.