简体   繁体   English

ACF转发器字段无结果

[英]No Results from ACF Repeater Field

I have a WordPress site with the ACF repeater field installed. 我有一个安装了ACF转发器字段的WordPress网站。 I have followed the video tutorials down to at and have tried every version of the template code examples on the site but I can't get anything to display at all, nothing. 我已经跟踪了视频教程,并尝试了网站上所有版本的模板代码示例,但是我什么也没显示。

My repeater field name 'carousel_images' and it has 3 sub fields, 'image', 'headline' and 'text'. 我的中继器字段名称为“ carousel_images”,它具有3个子字段,即“ image”,“ headline”和“ text”。

Can anyone help? 有人可以帮忙吗? I just want to display these fields on the front-end on my homepage, which is a static page using the 'front-page.php' template. 我只想在首页的前端显示这些字段,该页面是使用“ front-page.php”模板的静态页面。

My code: 我的代码:

<?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; ?>

EDIT 1 My repeater field was inside of a custom post type so I had to use the WP_Query to display the custom post type before I tried to display the repeater field. 编辑1我的转发器字段位于自定义帖子类型内,因此在尝试显示转发器字段之前,我必须使用WP_Query来显示自定义帖子类型。 Amended working code below. 下面修改了工作代码。

Thanks again. 再次感谢。

<?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; ?>

My repeater field was inside of a custom post type so I had to use the WP_Query to display the custom post type before I tried to display the repeater field. 我的转发器字段位于自定义帖子类型的内部,因此在尝试显示转发器字段之前,必须使用WP_Query来显示自定义帖子类型。 Amended working code below. 下面修改了工作代码。

Thanks again. 再次感谢。

<?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; ?>

Your repeater is not correct. 您的中继器不正确。 A repeater is a row. 中继器是一排。

<?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; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM