Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $taxonomyName = 'types';
- $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'hide_empty' => true));
- foreach($parent_terms as $parent_term ) {
- // display top level term name
- echo '<div class="archive_box"><header><h3>'. $parent_term->name . '</h3></header>';
- $child_terms = get_terms($taxonomyName, array('parent' => $parent_term->term_id, 'hide_empty' => true));
- foreach($child_terms as $child_term ) {
- // display name of all childs of the parent term
- echo '<div class="tax_section"><h3 class="tax_name">'. $child_term->name . '</h3>';
- echo '<ul class="archive_content">';
- //Loop goes here
- // max 3 posts from each child term, post type 'archives'
- $childposts = new WP_Query(
- 'post_type' => 'archives',
- 'showposts' => 3,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'types',
- 'field' => 'term_id',
- 'terms' => $child_term->term_id
- ),
- ),
- );
- foreach($childposts as $cp):
- echo '<li><a href="'.get_permalink($cp->ID).'">'.$cp->post_title.' <i class="fa fa-arrow-circle-o-right" aria-hidden="true"></i></a></li>';
- endforeach;
- //end loop
- echo'</ul><a href="'. $child_term->slug .'" class="button">More '. $child_term->name .'</a></div>';
- }
- //end archivebox
- echo '</div>';
- } ?>
Advertisement
Add Comment
Please, Sign In to add comment