• 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 == 'https://127.0.0.1/mysite/wp-content/themes/TEST/images/takeback.png' { echo "<a href=\"https://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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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 == 'https://127.0.0.1/mysite/wp-content/themes/TEST/images/takeback.png') { echo '<a href="https://www.mysite.net/url/here/"><img src="'.$withdrawal.'" /></a>' ;
    elseif($withdrawal=='') echo '<img src="'.$withdrawal.'" />&nbsp;';
    }?>
    Thread Starter ThorHammer

    (@thorhammer)

    esmi, thank you som much!!

    Thread Starter ThorHammer

    (@thorhammer)

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

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

    Anyone ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom fields – linked image’ is closed to new replies.