Custom fields - linked image (4 posts)

  1. ThorHammer
    Posted 7 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 == '' { 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 7 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 == '') { echo '<a href="http://www.mysite.net/url/here/"><img src="'.$withdrawal.'" /></a>' ;
    elseif($withdrawal=='') echo '<img src="'.$withdrawal.'" />&nbsp;';
  3. ThorHammer
    Posted 7 years ago #

    esmi, thank you som much!!

  4. ThorHammer
    Posted 7 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