Wordpress ACF中继器场循环

时间:2016-03-15 09:57:17

标签: php wordpress advanced-custom-fields

我正在尝试在我的wordpress前页模板中循环转发器字段 但由于某种原因,div是空的,似乎没有用。 我100%确定我的代码是正确的,所以一定有问题。 任何人都知道它可能是什么?

这就是我的循环的样子,字段键是正确的! :)

<?php
/**
 * Template Name: Front Page Template
 */
?>

<?php while(have_posts()) : the_post(); ?> 
    <?php if( have_rows('achtergrond_afbeeldingen') ): ?>
        <div class="slider-circles">
                <?php while ( have_rows('achtergrond_afbeeldingen') ) : the_row(); ?>
                    <p id="slide1" data-bgimage="<?php the_sub_field('image'); ?>" class="transparent-circle slick-active"></p>
                <?php endwhile; ?>
        </div>
    <?php endif; ?>
<?php endwhile; ?> 

这就是我的front-page.php的样子。我之前在其他项目中使用过这个有趣的东西,一切正常。现在我的屏幕只是空白,我不知道发生了什么。

3 个答案:

答案 0 :(得分:0)

如果have_rows('field_56e7d8bebb545')确实如此,请调试the_row();

var_dump(the_row());

你可以查看the_result,如果是空的,也许你必须为have_row设置第二个参数($ field_name, $ post_id

答案 1 :(得分:0)

尝试这个..因为你没有打印任何可以在浏览器中显示的东西..你只提供了div的数据属性。

在内部HTML中写一些内容可能会看到转发器值

<?php
/**
 * Template Name: Front Page Template
 */
?>

<?php while(have_posts()) : the_post(); ?> 
    <?php if( have_rows('achtergrond_afbeeldingen') ): ?>
        <div class="slider-circles">
                <?php while ( have_rows('achtergrond_afbeeldingen') ) : the_row(); ?>
                    <p id="slide1" data-bgimage="<?php the_sub_field('image'); ?>" class="transparent-circle slick-active"><?php the_sub_field('image'); ?></p>
                <?php endwhile; ?>
        </div>
    <?php endif; ?>
<?php endwhile; ?> 

答案 2 :(得分:0)

field_56e7d8bebb545是字段键,而不是字段名称。必须在have_rows()函数中使用字段名称。这可以在标签 -

旁边的高级自定义字段屏幕上找到

enter image description here

相关问题