• Resolved Glenn Ansley

    (@blepoxp)


    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

    (@blepoxp)

    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)

    (@otto42)

    www.ads-software.com Admin

    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

    (@blepoxp)

    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.