ACF转发器字段没有结果

ACF转发器字段没有结果

问题描述:

我有一个安装了ACF转发器字段的WordPress站点。我已经将视频教程记录下来,并尝试了网站上的每个版本的模板代码示例,但我什么也得不到,什么也没有显示。ACF转发器字段没有结果

我的转发字段名称'carousel_images',它有3个子字段,'图像','标题'和'文本'。

任何人都可以帮忙吗?我只想在主页的前端显示这些字段,这是一个使用'front-page.php'模板的静态页面。

我的代码:

<?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_Query显示自定义后类型之前,我试图显示中继器领域。修改下面的工作代码。

再次感谢。

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

我直放站领域里面装的是一个自定义的支柱式结构,所以我只好用WP_Query显示自定义后类型之前,我试图显示中继器领域。修改下面的工作代码。

再次感谢。

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

感谢您的评论,但不幸的是,这也行不通,这里没有任何代码显示。我的中继器字段是一个自定义帖子类型,它对任何事物都有影响吗? – 2014-09-08 08:24:16

+0

我现在工作,我不得不改变我的代码,因为中继器字段是在自定义帖子类型中。谢谢。 – 2014-09-08 09:02:45

+0

然后你应该接受答案,或者自己添加答案并接受(取决于哪个是真实的)。 – 2014-09-09 11:56:56