Skip to content

Instantly share code, notes, and snippets.

@tarikcayir
Last active September 7, 2015 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarikcayir/cb2e433b61b4a32a2821 to your computer and use it in GitHub Desktop.
Save tarikcayir/cb2e433b61b4a32a2821 to your computer and use it in GitHub Desktop.
<?php
// Category args.
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => false
);
// Get category list.
$categories = get_categories( $args );
// Listing all category.
foreach ($categories as $category): ?>
<div class="category-item">
<div class="category-item__title">
<?php echo $category->name; ?>
</div>
<div class="category-item__post-list">
<?php
// Query args.
$query_args = array(
'cat' => $category->term_id,
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC',
);
$query = new WP_Query( $query_args );
// Start the loop.
while ( $query->have_posts() ) : $query->the_post();
echo get_the_title().'<br/>';
// End the loop.
endwhile;
?>
</div>
</div>
<?php
endforeach;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment