Php 如果自定义字段值:显示,如果不显示,则显示另一个自定义字段
我试图在我的wordpress网站上显示两个不同的值: 它应该是,在点击任何缩略图(中心徽标)后 如果('music')中有字段值:显示 否则,在('image')字段中显示值 它实际上不起作用,代码好吗Php 如果自定义字段值:显示,如果不显示,则显示另一个自定义字段,php,wordpress,if-statement,advanced-custom-fields,custom-fields,Php,Wordpress,If Statement,Advanced Custom Fields,Custom Fields,我试图在我的wordpress网站上显示两个不同的值: 它应该是,在点击任何缩略图(中心徽标)后 如果('music')中有字段值:显示 否则,在('image')字段中显示值 它实际上不起作用,代码好吗 <?php $music = get_field('music'); $image = get_field('image'); if ($music!=''){ ?> <iframe width="600" height="166" scrolling="no" class
<?php
$music = get_field('music');
$image = get_field('image');
if ($music!=''){ ?>
<iframe width="600" height="166" scrolling="no" class="lightbox" class="frame" id="featherlight" frameborder="no" src="https://w.soundcloud.com/player/?url=<?php the_field('music'); ?>&color=1b1e25&theme_color=1b1e25&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>
<?php } else { ?>
<img src="<?php $image ?>" />
<?php endif; ?>
<?php } ?>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('post-thumbnails');
}
?>
如果get\u field()
为空,它实际上返回false,而不是空字符串。因此,您的代码总是运行iframe,因为$music
从来都不是空字符串(它要么是false,要么是您设置的某个值)。试试这个:
<?php if( get_field( 'music' ) ): ?>
<iframe width="600" height="166" scrolling="no" class="lightbox" class="frame" id="featherlight" frameborder="no" src="https://w.soundcloud.com/player/?url=<?php the_field( 'music' ); ?>&color=1b1e25&theme_color=1b1e25&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>
<?php else: ?>
<img src="<?php the_field( 'image' ); ?>" />
<?php endif; ?>
不,它不起作用。我尝试了不同的选择,但仍然不起作用,我不知道为什么。