Not able to target blog template page with conditional
-
I have some code in my functions file for the purpose of echoing css classes so I can swap out banners for different pages. It works great on all pages except for my blog index page.
I created a page for the blog index, defined it as blog page in ‘Settings’, and altered index.php to call the function in the banner area. In a conditional statement I’ve tried referencing both the page ID (’99’, as shown below) and also tried using if_page using the page slug, but neither works.
The code:
function is_tree($pid) { global $post; $anc = get_post_ancestors( $post->ID ); foreach($anc as $ancestor) { if(is_page() && $ancestor == $pid) { return true; } } if(is_page()&&(is_page($pid))) return true; else return false; }; function loadBannerStyles() { if(is_tree('105')){ echo 'banner-aboutus'; } else if(is_tree('92')){ echo 'banner-contact'; } else if(is_tree('99')){ echo 'banner-newsblog; } else { echo 'banner-default'; } }
This is one of those things that’s so right in front of my nose I can’t see it. How can I code a conditional to change the blog index the way I change all other pages?
Thanks!
- The topic ‘Not able to target blog template page with conditional’ is closed to new replies.