因此,我正在尝试创建一个CTA(call to action),将三张卡片添加到我的wordpress站点。我正在尝试插入PHP和ACF函数,以便它显示我的图像,目前它显示这些卡片的标题和正文,但不显示任何图像?我该如何修复它?
在我的acf中,我创建了四个子字段类型:"cta_image“、"cta_title”、"intro_text“和"cta_link”。在我的代码编辑器中,我插入了以下函数,到目前为止,在我的wordpress站点上,它显示了标题和介绍文本,但我不知道如何放置图像。
<?php
if ( have_rows( 'ctas' ) ) :
// Loop through rows (parent repeater).
while ( have_rows( 'ctas' ) ) :
the_row();
?>
<div class="title-wrapper">
<?php if ( get_sub_field( 'cta_title' ) ) : ?>
<h2><?php the_sub_field( 'cta_title' ); ?></h2>
<?php endif; ?>
</div>
<div class="body-text">
<?php print_r(get_sub_field('intro_text')); ?>
</div>
<?php
endwhile;
endif;
?>每次我插入函数来显示图像时,都会给出一个数据库错误,或者根本不显示任何图像。最终的作品应该看起来像下面的图像。我的只在一行中显示标题和正文。
发布于 2019-08-03 02:58:54
您有没有尝试过直接从documentation中使用这段代码?
<?php $image = get_sub_field('cta_image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>https://stackoverflow.com/questions/57331977
复制相似问题