Conditional statement for background image on child pages
-
Hi,
I’m trying to use a conditional statement to change the background image of a div depending what page you are on. It works fine for the parent pages, but I can’t seem to get to it work for the child pages (first if statement). I’m sure there’s a better way to do this, maybe using an array, unfortunately my php knowledge is a bit lacking.
I want to say ‘all pages with a parent of ‘shop” have the same background image.
Any help greatly received.
<?php if ( is_page('shop') || $post->post_parent == 'tablewares'): ?> <style type="text/css"> #container {background-color:#685f56;background-image:url(/wp-content/themes/hedgehogtheme/images/background_jugs.jpg);background-repeat: no-repeat;} </style> <?php elseif (is_page('home') ): // home ?> <style type="text/css"> #container {background-color:#685f56;background-image:url(/wp-content/themes/hedgehogtheme/images/background_jugs.jpg);background-repeat: no-repeat;} </style> <?php elseif (is_page('pottery') ): // pottery ?> <style type="text/css"> #container {background-color:#5a5454;background-image:url(/wp-content/themes/hedgehogtheme/images/background_candle.jpg);background-repeat:no-repeat;} </style> <?php elseif (is_page('bespoke-ceramics') ): // bespoke-ceramics ?> <style type="text/css"> #container {background-color:#6f6258;background-image:url(/wp-content/themes/hedgehogtheme/images/background_jug.jpg);background-repeat:no-repeat;} </style> <?php elseif (is_page('contact') ): // contact ?> <style type="text/css"> #container {background-color:#564d48;background-image:url(/wp-content/themes/hedgehogtheme/images/background_bowl.jpg);background-repeat:no-repeat;} </style> <?php elseif (is_page('about') ): // about ?> <style type="text/css"> #container {background-color:#6f6156;background-image:url(/wp-content/themes/hedgehogtheme/images/background_rings.jpg);background-repeat:no-repeat;} </style> <?php endif; // end the if, no images for other other categories ?>
The topic ‘Conditional statement for background image on child pages’ is closed to new replies.