我试图只显示一个链接,如果它有一个值。如果该字段为空,请隐藏PHP链接?
如何获得图像如果the_field imdb不是空的?
<a href="<?php the_field('imdb'); ?>" >
<img style="width:60px;"src="/img/link.png" /></a>
我试图只显示一个链接,如果它有一个值。如果该字段为空,请隐藏PHP链接?
如何获得图像如果the_field imdb不是空的?
<a href="<?php the_field('imdb'); ?>" >
<img style="width:60px;"src="/img/link.png" /></a>
因为我不想表现出对旧帖子的IMG或联系我解决它通过:
<?php
// assign image
$imdbimg = "<img src='http://mydomain.com/IMDb.png' class='imdb' />";
// imdb link from custom field
$imdblink = get_field('imdb');
?>
// display img and link on post newer then id 16
<?php global $post;
if ($post->ID >= 16){
echo '<a href="' . $imdblink . '" target="_blank"> ' . $imdbimg . '</a>';
}
?>
尝试: -
if(!empty(the_field('imdb'))){
<a href="<?php the_field('imdb'); ?>" ><img style="width:60px;"src="/img/link.png" /></a>
}
使用isset
if(isset(the_field('imdb'))&&!empty(the_field('imdb'))){
<img src=""/>
}
使用get_field();
代替the_filed();
。
没有必要为'isset()函数'从'空()'文档'空基本上是!isset($ var)||的简洁等价物$ var == false'。 – Jim