所以基本上我有一个主页和一个页脚。两者都是单独的.php文件。
我正在使用
ACF
对于此站点。
在文档之后,我在主页上为我的“灵活内容”创建了一个while循环,它可以工作,显示从CMS输入字段得到循环和连接的所有数据。
我的问题是在页脚,我有一个显示链接的while循环,但它不会显示
除非
我从主页中删除while循环,然后链接显示在页脚中。
我真的不明白为什么会这样,我测试了分配,让我的头围绕着这个,请帮助。
主页面代码:
<?php
// check if the flexible content field has rows of data
if( have_rows('flexible_content_field_name') ):
// loop through the rows of data
while ( have_rows('flexible_content_field_name') ) : the_row();
// check current row layout
if( get_row_layout() == 'gallery' ):
// check if the nested repeater field has rows of data
if( have_rows('images') ):
echo '<ul>';
// loop through the rows of data
while ( have_rows('images') ) : the_row();
$image = get_sub_field('image');
echo '<li><img src="' . $image['url'] . '" alt="' . $image['alt'] . '" /></li>';
endwhile;
echo '</ul>';
endif;
endif;
endwhile;
else :
// no layouts found
endif;
?>
<?php get_footer(); ?>
页脚代码:
<div class="links">
<?php
if( have_rows('footer_page_links', 'option') ):
var_dump("test");
while( have_rows('footer_page_links', 'option') ): the_row();
?>
<p><a href="<?php the_sub_field('footer_link'); ?>"><?php the_sub_field('footer_link_name'); ?></a></p>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php wp_footer(); ?>
我只想补充一点,即使是
vardump()
在执行循环时如果主页面不在页脚循环内,则在页脚中显示。页脚使用acf选项页->
LINK
如果页脚中的所有其他选项字段不在while循环中,也会显示这些字段。我删除了主页面while loop,然后删除了footer while loop,这只会发生在灵活的内容上,而我的其他带有循环的页面,它不包含灵活的内容,可以完美地工作。