Wordpress and Webdesign Forum go41 » WordPress Code Snippets

  1. If you want to load different header images, banners or an image in the sidebar, you can use a simple piece of php code.

    Let's say your normal image loads like this:

    <img src="<?php bloginfo('template_url'); ?>/images/logo.jpg" alt="" width="900px" height="250px"  />

    now you replace this full img src line with this:

    <?php if (is_page('1')) { ?>
    	<img src="<?php bloginfo('template_url'); ?>/images/logo1.jpg" alt=""  width="900px" height="250px" />
    <?php } elseif (is_page('2')) { ?>
    	<img src="<?php bloginfo('template_url'); ?>/images/logo2.jpg" alt="" width="900px" height="250px"  />
    <?php } elseif (is_page('3')) { ?>
    	<img src="<?php bloginfo('template_url'); ?>/images/logo3.jpg" alt="" width="900px" height="250px"  />
    <?php } else { ?>
    	<img src="<?php bloginfo('template_url'); ?>/images/logo.jpg" alt="" width="900px" height="250px"  />
    <?php } ?>

    this code will load logo1.jpg when you see page ID=1, logo2 for page with id 2 etc, if not one of this pages is loaded, it will 'else' switch to default logo.jpg

    do not forget to put the pictures into the images folder behind your theme folder and adjust the IDs to your page ID.

    Posted 2 years ago #

RSS feed for this topic

Reply

You must log in to post.

Join us! or log in (lost password?):