Created
December 6, 2013 22:30
-
-
Save kalenjohnson/7833248 to your computer and use it in GitHub Desktop.
Wordpress
Show all posts in each category
This file contains hidden or 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 | |
$category_IDs = get_all_category_ids(); | |
// Loop through categories | |
foreach ( $category_IDs as $category_ID ) : | |
$query = new WP_Query( array( | |
'cat' => $category_ID, | |
'posts_per_page' => - 1, | |
) ); | |
if ( $query->have_posts() ) : | |
// Show the category name first | |
$category_link = get_category_link( $category_ID ); | |
$category_name = get_the_category_by_ID( $category_ID ); | |
?> | |
<h2><a href="<?php echo $category_link; ?>"><?php echo $category_name; ?></a></h2> | |
<ul> | |
<?php while ( $query->have_posts() ) : $query->the_post(); ?> | |
<li> | |
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | |
</li> | |
<?php endwhile; ?> | |
</ul> | |
<?php endif; | |
endforeach; wp_reset_postdata(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment