我的双循环查询在这里有些不太正常,我不确定它到底是什么。基本上,我使用 ACF 在我的博客页面上提供了一个中继器字段,我可以在其中选择要在我的选项卡中显示的类别/分类法。因此,它可以很好地提取选项卡的名称,但我似乎无法在那里生成任何内容。有人建议我需要添加“reset_rows();”,我这样做了,但这似乎使页面永远加载,并且仍然没有创建任何实际内容。
这是我的循环。任何可以提供的帮助将不胜感激。
<!-- Nav Tabs -->
<ul class="nav nav-pills">
<?php if (have_rows('home_categories')) {
$i = 0;
while (have_rows('home_categories')) {
the_row();
$term = get_sub_field('categories'); ?>
<li class="<?php if ($i == 0) { echo ' active'; }?>">
<a href="#<?php echo $term->name; ?>" data-toggle="tab"><?php echo $term->name; ?></a>
</li>
<?php $i++;
}
} ?>
</ul>
<!-- Tab Content -->
<div class="tab-content clearfix">
<?php if (have_rows('home_categories')) {
$i = 0;
while (have_rows('home_categories')) {
the_row();
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => $term->taxonomy,
'terms' => array($term_id)
)
),
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'ASC',
);
$post = new WP_Query( $args );
while( $post->have_posts() ) : $post->the_post();
$term = get_sub_field('categories'); ?>
<div class="tab-pane fade<?php if ($i == 0) { echo ' in active'; }?>" id="<?php echo $term->name; ?>">
<?php the_post_thumbnail('thumbnail', array('class' => 'img-responsive img-thumbnail')); ?>
<a href="<?php echo get_permalink(); ?>"><h3><?php the_title(); ?></h3></a>
<?php the_excerpt(); ?>
</div>
<?php endwhile;
}
$i++;
}
wp_reset_postdata(); ?>
</div>