我正在显示这样的自定义字段:
<div class="blog_text">
<img src="<?php the_field('imagen_prensa'); ?>" />
</div>
我想让 img 仅在用户上传图像时出现,因为现在如果没有图像,则会出现损坏的图像符号。
我尝试了以下方法,但没有奏效:
<?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>