Image that changes depending on the Page Id
-
Hi all,
I want to have image, not a header image, that changes depending on the page id.I found this code snippet on this website
<?php $page_id=get_the_ID(); if(is_page()) { $image='head-image-'.$page_id.'.jpg'; }; if(!file_exists(STYLESHEETPATH.'/images/'.$image)) { $image='head-image.jpg'; } echo '<img src="'.get_stylesheet_directory_uri().'/images/'.$image.'" alt="" />'; ?>
I followed the instruction on the page. but it still did not work. Im wondering if it’s because I’m using a png instead of a Jpeg. How ever, no matter what I try I just can’t get it to work. ( Do i need to define “STYLESHEETPATH” SOMEWHERE?)
Unfortunately it is not online yet so i cannot show you. But I plan to put it in the index.php file. It is placed just above the “content” and will be 3d images of “Blog” “Video” etc.
This is how it is in my index file:
<div id="Pagetitleimage"><?php $page_id=get_the_ID(); if(is_page()) { $image='head-image-'.$page_id.'.png'; }; if(!file_exists(STYLESHEETPATH.'/images/'.$image)) { $image='head-image.png'; } echo '<img src="'.get_stylesheet_directory_uri()'/images/'.$image.'" alt="" />'; ?> </div>
I understand about Css styling, I just want my page to find the images I have made in the first place so that I can apply the styling
Please help out,
Thanks
- The topic ‘Image that changes depending on the Page Id’ is closed to new replies.