This should get you pretty close. The key is to use iterating loops and check which iteration you’re on to determine whether or not to output a new <div class="row">
, open or close a <ul>
, etc.
Note that one you are in a loop, you can just use the_permalink()
and the_title()
because the query already grabbed them, no need to echo get_the_title()
etc.
<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="https://wordpress.stackexchange.com/questions/262224/<?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>