Jump to content

if link exists then show image


mstone

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.