Last active
April 29, 2016 23:24
-
-
Save yratof/23b3b8050facf9b013e1 to your computer and use it in GitHub Desktop.
List all taxonomies and loop their posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Loop for taxonomies to show their posts | |
*/ | |
$taxonomy = 'brand'; | |
$terms = get_terms($taxonomy); | |
foreach ($terms as $term) { | |
$wpq = array ( | |
'taxonomy' => $taxonomy, | |
'term' =>$term->slug, | |
'orderby' => 'id' | |
); | |
$myquery = new WP_Query ($wpq); | |
$article_count = $myquery->post_count; ?> | |
<div id="taxonomies" class="tax__archive cf"> | |
<h3 class="tax__archive--title"><?php echo ($term->name); ?></h3> | |
<?php if ($article_count) { ?> | |
<ul class="tax__archive--list"> | |
<?php while ($myquery->have_posts()) : $myquery->the_post(); ?> | |
<li class="tax__archive--item"> | |
<a class="tax__archive--link" href="<?php the_permalink();?>"><?php the_title(); ?></a> | |
</li> | |
<?php endwhile; ?> | |
</ul> | |
<?php } ?> | |
</div> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment