0

The explanation for this line is that Anchor doesn't display the image from the custom field correctly. So I had to add the missing part of the path. It works just fine, but now the problem is that I get horrendous icons on Safari when there is no image fetched in the field image:

<?php echo "<img src='http://www.firstpartoftheurl/" . article_custom_field('image') . "' alt=' ' height='300' >"; ?>

May I show this line only when the custom field is populated? And how can I hide custom fields when they are empty?

Laurel
  • 5,965
  • 14
  • 31
  • 57
Marc
  • 35
  • 1
  • 7

2 Answers2

0

This is how I solved it:

<?php
$image = article_custom_field('image');
if (!empty($image)) { 
echo "<img src= 'http://www.firstpartoftheurl".article_custom_field('image')."' alt='blabla ".article_title()."'>"; //if there is image show it
} else {
//if not do nothing
} ?>

I hope it helps. It works for me but if someone has a better solution, please let us know.

Marc
  • 1
0

Shorter still:

<?php if (article_custom_field('featured-img')) :?>
      <img src="<?php echo article_custom_field('featured-img')?>" alt="<?php echo article_title(); ?>" />
<?php endif; ?>    

If article_custom_field() is not returning the full URL, there might be something up with your server configuration, because this has always worked for me. Otherwise, just prepend $_SERVER['SERVER_NAME']... this is better than hard-coding the URL.

There is documentation on the function here which also explains how to use its fallback: http://anchorcms.com/docs/function-reference/articles

invot
  • 533
  • 7
  • 30