Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Created September 18, 2013 22:26
Show Gist options
  • Save claudiosanches/6616614 to your computer and use it in GitHub Desktop.
Save claudiosanches/6616614 to your computer and use it in GitHub Desktop.
WordPress - List all posts gruped by category.
<?php
foreach ( get_categories( array( 'orderby' => 'name', 'order' => 'ASC' ) ) as $category ) {
$posts = get_posts( array(
'showposts' => -1,
'category__in' => array( $category->term_id ),
'ignore_sticky_posts' => 1
) );
if ( $posts ) {
echo '<h4>' . __( 'Categoria:' ) . ' <a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a></h4>';
foreach ( $posts as $post ) {
setup_postdata( $post );
echo '<p><a href="' . get_permalink() . '">' . get_the_title() . '</a></p>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment