January 6, 201214 yr Hey guys, Looking for some advice on a site I'm building for a client, scratching my head about the best way to approach this problem. My basic layout looks like: [Logo] - [Navigation] [big Image] [Testimonial Slider] [Content] I've put the Logo, Nav, Big Image and Testimonials in the Header.php file, so it's the same across all pages, simple! But now the client says they want a different image on every page! (6 pages) And I'm debating the best way to do this? Is there a way of avoiding having to make a custom template for every different page? Thanks, Chris
January 6, 201214 yr Wordpress puts classes on the body tag, use css to set the image url depending on each page's body class
January 6, 201214 yr Author How would you do that in CSS? Set it up as a background image and do it that way? So Body.ClassName BigImage { bakground-image:url('url.jpg'); } - something a long those lines? Thanks for your quick response!
January 6, 201214 yr You could do it with CSS, by changing the background image of a HTML tag according to the body class. To get the classes applied to the body tag, do this: <body <?php body_class();?>> Another way of doing it, is, using the is_page() template tag, e.g: <?php if ( is_page('About') ) { ?> <img src="<?php bloginfo('template_url')?>/images/about.gif" title="" /> <?php } ?> <?php if ( is_page('Contact') ) { ?> <img src="<?php bloginfo('template_url')?>/images/contact.gif" title="" /> <?php } ?> Edited January 6, 201214 yr by Pedro
January 6, 201214 yr Body.ClassName BigImage { bakground-image:url('url.jpg'); } - something a long those lines? Essentially yes. body.pagename1 .mainimage {background-image:url('url1.jpg');} body.pagename2 .mainimage {background-image:url('url2.jpg');} body.pagename3 .mainimage {background-image:url('url3.jpg');} body.pagename4 .mainimage {background-image:url('url4.jpg');} etc... Another way of doing it, is, using the is_page() template tag, e.g: <?php if ( is_page('About') ) { ?> <img src="<?php bloginfo('template_url')?>/images/about.gif" title="" /> <?php } ?> <?php if ( is_page('Contact') ) { ?> <img src="<?php bloginfo('template_url')?>/images/contact.gif" title="" /> <?php } ?> This is how I originally thought to do it and it does the same job, just more to write
January 6, 201214 yr Use the page's featured image. Set a custom size for it in your theme's functions.php, and you can get the featured image outside of the Loop by passing $post->ID.
Create an account or sign in to comment