WordPress.org

Ready to get started?Download WordPress

Forums

Custom fields - linked image (4 posts)

  1. ThorHammer
    Member
    Posted 5 years ago #

    I want to display (several) images from a custom field. If one of these images are presented, it is supposed to be linked. But I only get parse errors when trying to link it.
    Here is the code:

    <?php $withdrawals=get_post_meta($post->ID,"withdrawals",false); ?>
    <?php foreach($withdrawals as $withdrawal);
    if($withdrawal == 'http://127.0.0.1/mysite/wp-content/themes/TEST/images/takeback.png' { echo "<a href=\"http://www.mysite.net/url/here/"><img src="".$withdrawal."\" /></a>" ; }
    elseif($withdrawal=='' { echo "<img src=\"".$withdrawal."\" />&nbsp;"; } ?>

    PHP is hard for me..anyone out there with a bright eye and a brigt idea?

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    You're missing brackets for the if/elsif and foreach. Try:

    <?php $withdrawals=get_post_meta($post->ID,'withdrawals',false); ?>
    <?php foreach($withdrawals as $withdrawal) {
    if($withdrawal == 'http://127.0.0.1/mysite/wp-content/themes/TEST/images/takeback.png') { echo '<a href="http://www.mysite.net/url/here/"><img src="'.$withdrawal.'" /></a>' ;
    elseif($withdrawal=='') echo '<img src="'.$withdrawal.'" />&nbsp;';
    }?>
  3. ThorHammer
    Member
    Posted 5 years ago #

    esmi, thank you som much!!

  4. ThorHammer
    Member
    Posted 5 years ago #

    Damn... I got a parse error.. on the last line:

    elseif($withdrawal=='') echo '<img src="'.$withdrawal.'" />&nbsp;';

    Anyone ?

Topic Closed

This topic has been closed to new replies.

About this Topic