Php ACF中继器字段没有结果
我有一个安装了ACF repeater字段的WordPress站点。我跟随视频教程一直到t,并在网站上尝试了每个版本的模板代码示例,但我根本无法显示任何内容,什么都没有 我的中继器字段名为“carousel_images”,它有3个子字段,“image”、“headline”和“text” 有人能帮忙吗?我只想在我的主页的前端显示这些字段,这是一个使用“FrontPage.php”模板的静态页面 我的代码:Php ACF中继器字段没有结果,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我有一个安装了ACF repeater字段的WordPress站点。我跟随视频教程一直到t,并在网站上尝试了每个版本的模板代码示例,但我根本无法显示任何内容,什么都没有 我的中继器字段名为“carousel_images”,它有3个子字段,“image”、“headline”和“text” 有人能帮忙吗?我只想在我的主页的前端显示这些字段,这是一个使用“FrontPage.php”模板的静态页面 我的代码: <?php if(get_field('carousel_images')): ?
<?php if(get_field('carousel_images')): ?>
<div>
<?php while(has_sub_field('carousel_images')): ?>
<img src="<?php the_sub_field('image'); ?>">
<div class="caption">
<h3><?php the_sub_field('headline'); ?></h3>
<p><?php the_sub_field('text'); ?></p>
<a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
<a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></a>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
">
编辑1
我的转发器字段位于自定义帖子类型的内部,因此我必须使用WP_查询来显示自定义帖子类型,然后才能尝试显示转发器字段。下面修改了工作代码
再次感谢
<?php
$args = array(
'post_type' => 'home_carousel_image'
);
$the_query = new WP_Query( $args );
?>
<!-- WP_Query WordPress loop -->
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php if(get_field('carousel_images')): ?>
<?php while(has_sub_field('carousel_images')): ?>
<div>
<img src="<?php the_sub_field('image'); ?>">
<div class="caption">
<h3><?php the_sub_field('headline'); ?></h3>
<p><?php the_sub_field('text'); ?></p>
<a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
<a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></span></a>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; else: ?>
<!-- Displayed if no posts or pages are available -->
<p>There are no posts or pages here!</p>
<?php endif; ?>
<?php
$args = array(
'post_type' => 'home_carousel_image'
);
$the_query = new WP_Query( $args );
?>
<!-- WP_Query WordPress loop -->
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php if(get_field('carousel_images')): ?>
<?php while(has_sub_field('carousel_images')): ?>
<div>
<img src="<?php the_sub_field('image'); ?>">
<div class="caption">
<h3><?php the_sub_field('headline'); ?></h3>
<p><?php the_sub_field('text'); ?></p>
<a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
<a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></span></a>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; else: ?>
<!-- Displayed if no posts or pages are available -->
<p>There are no posts or pages here!</p>
<?php endif; ?>
">
这里没有帖子或页面
您的中继器不正确。中继器是一排
<?php if (have_rows('carousel_images')): ?>
<div>
<?php while (have_rows('carousel_images')): the_row(); ?>
<img src="<?php the_sub_field('image'); ?>">
<div class="caption">
<h3><?php the_sub_field('headline'); ?></h3>
<p><?php the_sub_field('text'); ?></p>
<a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
<a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></a>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
">
我的转发器字段位于自定义帖子类型中,因此我必须使用WP\u查询来显示自定义帖子类型,然后才能尝试显示转发器字段。下面修改了工作代码
再次感谢
<?php
$args = array(
'post_type' => 'home_carousel_image'
);
$the_query = new WP_Query( $args );
?>
<!-- WP_Query WordPress loop -->
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php if(get_field('carousel_images')): ?>
<?php while(has_sub_field('carousel_images')): ?>
<div>
<img src="<?php the_sub_field('image'); ?>">
<div class="caption">
<h3><?php the_sub_field('headline'); ?></h3>
<p><?php the_sub_field('text'); ?></p>
<a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
<a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></span></a>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; else: ?>
<!-- Displayed if no posts or pages are available -->
<p>There are no posts or pages here!</p>
<?php endif; ?>
<?php
$args = array(
'post_type' => 'home_carousel_image'
);
$the_query = new WP_Query( $args );
?>
<!-- WP_Query WordPress loop -->
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php if(get_field('carousel_images')): ?>
<?php while(has_sub_field('carousel_images')): ?>
<div>
<img src="<?php the_sub_field('image'); ?>">
<div class="caption">
<h3><?php the_sub_field('headline'); ?></h3>
<p><?php the_sub_field('text'); ?></p>
<a href="#" class="hero-button" data-reveal-id="loginModal">Login <span><i class="fa fa-user"></i></span></a>
<a href="#" class="hero-button" data-reveal-id="registerModal">Register <span><i class="fa fa-check-square"></i></span></a>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; else: ?>
<!-- Displayed if no posts or pages are available -->
<p>There are no posts or pages here!</p>
<?php endif; ?>
">
这里没有帖子或页面
感谢您的评论,但不幸的是,这也不起作用,代码所在的位置没有显示任何内容。我的repeater字段是一个自定义post类型,这对任何事情都有影响吗?我现在可以使用它了,我必须更改代码,因为repeater字段位于自定义post类型中。谢谢。你应该接受答案,或者自己添加答案并接受(取决于哪个答案是正确的)。斯蒂芬,记住你在最初的帖子中从未提到过它在CPT中。艾布林-纠正,我的错误,我们都犯了。。。无论如何,谢谢你的回答。