Targeting a specific category to replace background images
-
I’m attempting to change the background image based on what page or category the user is on. I can’t seem to get the code to work for the categories though.
The url: https://asvpart.com/new/category/portfolio/
the code:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php $cat_obj = $wp_query->get_queried_object(); $cat_id = $cat_obj->cat_ID; ?> <?php if (is_page('5') ): // page home ?> <style type="text/css"> body {background-color:#000;background-image:url(https://asvpart.com/new/wp-content/uploads/2011/07/bkgrnd_gallery.jpg);background-repeat:no-repeat; background-size: 100%;} </style> <?php elseif (in_category('portfolio') ): // category 5 ?> <style type="text/css"> body {background-color:#000;background-image:url(https://asvpart.com/new/wp-content/uploads/2011/07/bkgrnd_gallery.jpg);background-repeat:no-repeat; background-size: 100%;} </style> <?php endif; ?>
I’m not sure why the ‘portfolio’ will not target the ‘portfolio’ page.
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Targeting a specific category to replace background images’ is closed to new replies.