Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果自定义字段值:显示,如果不显示,则显示另一个自定义字段_Php_Wordpress_If Statement_Advanced Custom Fields_Custom Fields - Fatal编程技术网

Php 如果自定义字段值:显示,如果不显示,则显示另一个自定义字段

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

我试图在我的wordpress网站上显示两个不同的值: 它应该是,在点击任何缩略图(中心徽标)后

如果('music')中有字段值:显示

否则,在('image')字段中显示值

它实际上不起作用,代码好吗

<?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'); ?>&amp;color=1b1e25&amp;theme_color=1b1e25&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;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' ); ?>&amp;color=1b1e25&amp;theme_color=1b1e25&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false"></iframe>
<?php else: ?>
  <img src="<?php the_field( 'image' ); ?>" />
<?php endif; ?>


不,它不起作用。我尝试了不同的选择,但仍然不起作用,我不知道为什么。