is_page_template function breaks after the loop
-
I’m changing between black and white images on different pages by using
is_page_template(pagename.php)
to set a string value to either_rvs
(stands for reverse) or empty and then inserting the returned string into the image URL.Everything was working across several pages. If I add a post loop to my home page ‘front-page.php’ the correct string is passed to images above the loop but not to images beneath the loop. I read the codex relating to
<?php wp_reset_query(); ?>
and integrated it after the loop but it does not fix the problem.This is in my functions.php…
// Set page styles function reverse_styles() { $reverse = '_rvs'; if ( !is_page_template('about.php') && !is_page_template('front-page.php') ) { $reverse = '_rvs'; } else { $reverse = ''; } return $reverse; }
I call the function in my page as follows…
<img class="myClass" src="<?php echo get_stylesheet_directory_uri() ?>/images/imageName<?php echo reverse_styles() ?>.png" alt="" />
The resulting URL in the browser is either
.../images/imageName.png
or.../images/imageName_rvs.png
Any suggestions why it breaks after the loop?
- The topic ‘is_page_template function breaks after the loop’ is closed to new replies.