Home
PDF Print E-mail
Written by Administrator   
Monday, 22 February 2010 12:29

How to create different image (style) header on different pages in WordPress?

In my last project, I needed to create unique header image for every pages: Home, Services, Portfolio, Contact, Blog.

So i fond Wordpress function: is_page().

How it works?

Open folder: wp-content/themes/YourThemeName/header.php and add this code to the bottom:


<?php if(is_page('Services')) :?>
<img src="/<?php bloginfo('template_url'); ?>/images/services.png" alt="Services"/>
<?php endif;?>

<?php if(is_page('Portfolio')) :?>
<img src="/<?php bloginfo('template_url'); ?>/images/portfolio.png" alt="Portfolio"/>
<?php endif;?>

<?php if(is_page('Contact')) :?>
<img src="/<?php bloginfo('template_url'); ?>/images/contact.png" alt="Contact"/>
<?php endif;?>

<?php if(is_page('Blog')) :?>
<img src="/<?php bloginfo('template_url'); ?>/images/blog.png" alt="Blog"/>
<?php endif;?>

What we have in this code: is_page('Services') where Service is the name of Service page, you can use ID's of your pages: is_page('43').

bloginfo('template_url') this is path to Your theme, Wordpress adding this automatically.

Thanks, Vlad.


 

Comments 

 
#1 2010-03-14 01:11
I hope this is an easy question. I want to use is_page for my top navigation. I have links with classes inside of list items. What I want to happen is when I am on the "portfolio" or "services" page is to change the style of these list items to change the position of the background image accordingly. Thanks!
Quote
 
 
#2 2010-03-16 16:31
2 marshall Moore. I think you don't need to use is_page, you can just add CSS styles to you items. I wrote article about adding roll-over image menu in WP without JS: http://www.sopov.com/component/content/article/65-how-create-rollover-image-menu-in-wordpress.html
Quote
 

Add comment


Security code
Refresh

© 2010. Sopov.com