mstone Posted May 7, 2012 Share Posted May 7, 2012 Hey everyone, I could use some help with this one.. I need to create some php code to switch images when a certain page loads. For example: These are the pages, test1, test2,test3, so when you click on the test1 link in the navigation a certain image would show up : something like this: If test1 exists then show image1.jpg If test2 exists then show image2.jpg If test3 exists then show image2.jpg. I am doing this in wordpress and I can't figure out the if then statement.. Does anyone have any ideas?? thanks Quote Link to comment https://forums.phpfreaks.com/topic/262219-if-link-exists-then-show-image/ Share on other sites More sharing options...
mstone Posted May 7, 2012 Author Share Posted May 7, 2012 figured it out! <div id="site_button"> <?php if(is_page('page1')) { echo '<a href="#" target="_blank"><img src="image source link" alt="visit-button" border="0" width="212" height="52" /></a>'; } elseif(is_page('page2')) { echo '<a href="#" target="_blank"><img src="image source link" alt="visit-button" width="212" border="0" height="52" /></a>'; } elseif(is_page('page3')) { echo '<a href="#" target="_blank"><img src="image source link" alt="visit-button" width="212" border="0" height="52" /></a>'; } elseif(is_page('page4')) { echo '<a href="#" target="_blank"><img src="image source link" alt="visit-button" width="212" border="0" height="52" /></a>'; } elseif(is_page('page5')) { echo '<a href="#" target="_blank"><img src="image source link" border="0" alt=visit-button"" width="212" height="52" /></a>'; } elseif(is_page('page6)) { echo '<a href="#" target="_blank"><img src="image source link" border="0" alt="visit-button" width="212" height="52" /></a>'; } // continue with elseif lines // else { echo 'test complete'; } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/262219-if-link-exists-then-show-image/#findComment-1343807 Share on other sites More sharing options...
Jessica Posted May 7, 2012 Share Posted May 7, 2012 You realize the link inside each of those is identical? Why not create a string for the link based on the page? $link_url = 'image'.$pageNum.'.jpg'; Quote Link to comment https://forums.phpfreaks.com/topic/262219-if-link-exists-then-show-image/#findComment-1343820 Share on other sites More sharing options...
colleyboy Posted May 7, 2012 Share Posted May 7, 2012 This might be me being a little over OCD but I will say it anyway. Try and put extras within repeated tags in the same order (i.e: width, height etc). This way when you look back at the coding its just a bit simpler to read. Other than the duplicate links I think you have got it though . Regards, Ian Quote Link to comment https://forums.phpfreaks.com/topic/262219-if-link-exists-then-show-image/#findComment-1343826 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.