Php 使用锚定CMS隐藏图像的空自定义字段
对此行的解释是,锚点无法正确显示自定义字段中的图像。因此,我不得不添加路径中缺失的部分。它工作得很好,但现在的问题是,当在字段图像中没有获取图像时,Safari上会出现可怕的图标:Php 使用锚定CMS隐藏图像的空自定义字段,php,custom-fields,anchor-cms,Php,Custom Fields,Anchor Cms,对此行的解释是,锚点无法正确显示自定义字段中的图像。因此,我不得不添加路径中缺失的部分。它工作得很好,但现在的问题是,当在字段图像中没有获取图像时,Safari上会出现可怕的图标: <?php echo "<img src='http://www.firstpartoftheurl/" . article_custom_field('image') . "' alt=' ' height='300' >"; ?> 我是否可以仅在填充自定义字段时显示此行? 当自定义字
<?php echo "<img src='http://www.firstpartoftheurl/" . article_custom_field('image') . "' alt=' ' height='300' >"; ?>
我是否可以仅在填充自定义字段时显示此行?
当自定义字段为空时,如何隐藏它们?我就是这样解决的:
<?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
} ?>
我希望有帮助。这对我很有效,但如果有人有更好的解决方案,请告诉我们。更简短:
<?php if (article_custom_field('featured-img')) :?>
<img src="<?php echo article_custom_field('featured-img')?>" alt="<?php echo article_title(); ?>" />
<?php endif; ?>
“alt=”“/>
如果article\u custom\u field()
没有返回完整的URL,可能是服务器配置有问题,因为这对我来说一直都很有效。否则,只需在$\u server['server\u NAME']
前面加上前缀,这比硬编码URL要好
这里有关于该函数的文档,其中还解释了如何使用其回退: