Design Locker
Member
Posted 6 months ago #
Hello All,
When I open a particular page I want wordpress to check the page ID and if it is a certain page ID then insert "image1". If page ID equals another predefined ID then insert "image2" etc.
In other words;
If page ID equals 15, insert image1.jpg
Else
If page ID equals 16, insert image2.jpg
Else
If page ID equals 17, insert image3.jpg
etc...
Generally I need the code to be able to achieve this as I really am not all that good at PHP.
I look forward to your help and thank you.
Design Locker
Member
Posted 6 months ago #
Thanks for reply. Have spent hours looking at this page, my PHP is non-existent and below is all I can come up with;
<?php
if ( is_page( '15' ) || '2' == $post->post_parent ) {
<img src="image1.jpg">;
} elseif ( is_page( '16' ) || '56' == $post->post_parent ) {
<img src="image2.jpg">;
} else {
<img src="image3.jpg">;
}
?>
Thanks for help.
Get rid of the quotes around your Page ids.
Design Locker
Member
Posted 6 months ago #
thanks esmi; do you think this looks right?
<?php
if ( is_page(15) {
<img src="image1.jpg">;
} elseif ( is_page(16) {
<img src="image2.jpg">;
} else {
<img src="image3.jpg">;
}
?>
Your logic is correct but your syntax is all wrong. Try:
<?php if ( is_page(15) ) $img = 'image1.jpg';
elseif ( is_page(16) ) $img = 'image2.jpg';
else $img = 'image3.jpg';
if( isset( $img) ) ?><img src="<?php echo $img;?>">