Php 如果自定义字段存在,则使用自定义字段的URL回显图像
不起作用,我得到了意想不到的字符串Php 如果自定义字段存在,则使用自定义字段的URL回显图像,php,Php,不起作用,我得到了意想不到的字符串 <?php $customfield = get_post_meta($post->ID, 'bannerurl', true); if ($customfield == '') { echo '<img src="<?php echo get_post_meta($post->ID, 'bannerurl', true); ?>" alt="text" />'; } ?
<?php $customfield = get_post_meta($post->ID, 'bannerurl', true);
if ($customfield == '') {
echo '<img src="<?php echo get_post_meta($post->ID, 'bannerurl', true); ?>" alt="text" />';
}
?>
尝试以下方法:
//if $customfild exist than below will execute else "No Data".
if (isset($customfield)) {
echo '<img src="'.get_post_meta($post->ID, 'bannerurl', true).'" alt="text" />'; }
else
echo "No Data";
//如果$customfild存在,则下面将执行“无数据”。
if(isset($customfield)){
回显'ID',bannerurl',true)。''alt=“text”/>';}
其他的
回声“无数据”;
试试这个
<?php $customfield = get_post_meta($post->ID, 'bannerurl', true);
if ($customfield == '') {
echo '<img src="get_post_meta($post->ID, 'bannerurl', true)" alt="text" />';
}
?>
如果($customfield=''){
回显'ID',bannerurl',true)。''alt=“text”/>';}
要检查
$customfield
是否存在,请使用isset()
方法-您可以阅读它 记住:所以不是调试tool@AlmaDoMundo你错了-特定的编程问题
也意味着debugging@AlmaDoMundo请阅读pagedon’t care我正在使用它,但如果自定义字段不存在,如何使它不返回任何内容?在if()条件之前,您可以像print\r($customfield)那样执行打印操作吗看看会有什么价值。
if ($customfield == '') {
echo '<img src="'.get_post_meta($post->ID, 'bannerurl', true).'" alt="text" />'; }