这应该会让你离得很近。关键是使用迭代循环并检查正在进行的迭代,以确定是否输出新的<div class="row">
, 打开或关闭<ul>
, 等
请注意,您处于循环中的一个the_permalink()
和the_title()
因为查询已经抓到了它们,所以不需要echo get_the_title()
等
<div class="clientsListRow"><?php
$post_type = \'clients\';
$taxonomies = get_object_taxonomies(array(\'post_type\' => $post_type));
foreach($taxonomies as $taxonomy) :
$terms = get_terms($taxonomy);
for($t=1; $t<=count($terms); $t++) {
// if "t" is 1 or a multiple of 7, start a new row
if($t == 1 || $t%7 == 0) { ?><div class="row"><?php }
// if "t" is 1 or a multiple of 4, start a new list
if($t == 1 || $t%4 == 0) { ?><ul><?php } ?>
<li>
<a href="<?php echo get_term_link($term->term_id); ?>"><?php echo $term->name; ?></a>
<?php
$args = array(
\'post_type\' => $post_type,
\'posts_per_page\' => -1, //show all posts
\'tax_query\' => array(
array(
\'taxonomy\' => $taxonomy,
\'field\' => \'slug\',
\'terms\' => $term->slug,
)
)
);
$posts = new WP_Query($args);
if($posts->have_posts()) : ?>
<ul>
<?php while($posts->have_posts() ) : $posts->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</li>
<?php // if "t" is a multiple of 3, or the very last item, close the list
if($t%3 == 0 || $t == count($terms)) { ?></ul><?php
// if "t" is a multiple of 6, or the very last item, close the row
if($t%6 == 0 || $t == count($terms)) { ?></div><!-- end row --><?php
}
endforeach; ?>
</div>