我将如下展示一个自定义字段:
```html
我希望只有用户上传了图片时,图片才会出现,因为现在如果没有图片,就会出现一个损坏的图片符号。
我尝试过以下方法,但并没有起作用:
可以实现吗?
编辑:
使用以下答案后,现在这是代码,但它只显示一个空白页面:
我正在这样展示一个自定义字段:
```<div class="blog_text">
<img src="<?php the_field('imagen_prensa'); ?>" />
</div>
我希望只有用户上传了图片时,图片才会出现,因为现在如果没有图片,就会出现一个损坏的图片符号。
我尝试过以下方法,但并没有起作用:
<?php if (get_field('imagen_prensa') != ''): ?>
<img src="<?php the_field('imagen_prensa'); ?>" />
<?php endif; ?>
可以实现吗?
编辑:
使用以下答案后,现在这是代码,但它只显示一个空白页面:
<div id="blog_interior">
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<article>
<div class="article_date"><?php the_time('d/m/Y'); ?></div>
<h2><?php echo get_the_title(); ?></h2>
<div class="blog_text">
<?php if ( !empty(the_field('imagen_prensa')) ): ?>
<img src="<?php echo the_field('imagen_prensa'); ?>" />
<?php endif; ?>
<div class="video_prensa"><?php the_field('video_prensa'); ?></div>
<?php the_content() ?>
</div>
</article>
<?php endwhile; ?>
<div class="back">
</div>
</div>
var_dump()
或print_r()
来转储get_field('imagen_prensa')
的返回值,它可能不是空值(null、false、''、0等)。 - Hikaru-Shindo