Title: Adding Link to php conditional
Last modified: August 18, 2016

---

# Adding Link to php conditional

 *  Resolved [Glenn Ansley](https://wordpress.org/support/users/blepoxp/)
 * (@blepoxp)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/adding-link-to-php-conditional/)
 * I have the following code in my loop.
 *     ```
       foreach(get_post_custom_values('post_image') as $value) {
       			echo '<img src="/images/' . $value . '.jpg" width="240" height="60" alt="" />';
       				}
       				else : echo '<img src="/images/imagenotfound.jpg" width="240" height="60" alt="" />';
       			endif; ?>
       ```
   
 * I am having a hard time making the image a link because of quotes vs. double 
   quotes and my ability to call the permarlink function built into wordpress. If
   I use a single quote: `<a href='<?php get_permalink(); ?>'>` I get parse erros.
   If I use double quotes: `<a href="<?php get_permalink(); ?>">` the php doesn’t
   translate.
 * I realize my problem is in that i’ve already initiate php, but I can’t figure
   out how to do it. Could someone help me.
    The simple form of the question is 
   this: How can I turn the results of my custom value query into a link?
 * Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [Glenn Ansley](https://wordpress.org/support/users/blepoxp/)
 * (@blepoxp)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/adding-link-to-php-conditional/#post-522074)
 * Is this a simple php issue I’m unaware of or is it more difficult? Has no one
   answered because you’re rolling your eyes or because you don’t know what I’m 
   asking? Thanks.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 4 months ago](https://wordpress.org/support/topic/adding-link-to-php-conditional/#post-522079)
 * Seems complicated. Try this instead.
 *     ```
       <?php
       ... whatever you have above the foreach ...
       foreach(get_post_custom_values('post_image') as $value) {
       ?>
       <img src="/images/<?php echo $value; ?>.jpg" width="240" height="60" alt="" />
       <?php } else { ?>
       <img src="/images/imagenotfound.jpg" width="240" height="60" alt="" />
       <?php } ?>
       ```
   
 * You can open and close the PHP blocks anywhere you like. Using complex echo statements
   just makes things difficult, IMO.
 * Also, “get_permalink()” is probably not what you want to use. Try “the_permalink()”
   instead.
 *  Thread Starter [Glenn Ansley](https://wordpress.org/support/users/blepoxp/)
 * (@blepoxp)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/adding-link-to-php-conditional/#post-522083)
 * That worked great. I really appreciate it. I didn’t think it could have been 
   that difficult. Thanks again!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Adding Link to php conditional’ is closed to new replies.

## Tags

 * [conditionals](https://wordpress.org/support/topic-tag/conditionals/)
 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Glenn Ansley](https://wordpress.org/support/users/blepoxp/)
 * Last activity: [19 years, 4 months ago](https://wordpress.org/support/topic/adding-link-to-php-conditional/#post-522083)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
