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?

4

2 回答 2

0

这就是我解决它的方法:

<?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
} ?>

我希望它有所帮助。它对我有用,但如果有人有更好的解决方案,请告诉我们。

于 2014-08-03T21:17:39.213 回答
0

更短的:

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

如果article_custom_field()没有返回完整的 URL,那么您的服务器配置可能有问题,因为这一直对我有用。否则,只需添加$_SERVER['SERVER_NAME']...这比对 URL 进行硬编码要好。

这里有关于函数的文档,它还解释了如何使用它的后备:http ://anchorcms.com/docs/function-reference/articles

于 2014-09-16T17:48:51.273 回答