Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created May 2, 2014 14:53
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 jaredatch/25b4c9fde3b2773f0c21 to your computer and use it in GitHub Desktop.
Save jaredatch/25b4c9fde3b2773f0c21 to your computer and use it in GitHub Desktop.
<?php
/**
* Creates nested date archive list for a specific category
*
* @since 1.0.0
*/
function ja_category_archive_list() {
global $post;
$posts = get_posts( 'posts_per_page=-1&cat=154' );
$year = '';
$month = '';
echo '<ul class="date-archive-list">';
foreach( $posts as $post ) {
setup_postdata( $post );
if ( ucfirst( get_the_time( 'F' ) ) != $month && $month != '' ){
echo '</ul></li>';
}
if ( get_the_time( 'Y' ) != $year && $year != '' ){
echo '</ul></li>';
}
if ( get_the_time( 'Y' ) != $year ){
$year = get_the_time('Y');
echo '<li><h2>' . $year . '</h2><ul class="monthly-archives">';
}
if ( ucfirst( get_the_time( 'F' ) ) != $month ){
$month = ucfirst( get_the_time( 'F' ) );
echo '<li><h6>' . $month . '</h6><ul>';
}
echo '<li>';
echo '<span class="date">' . get_the_time( 'jS' ) . '</span> - ';
echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
echo '</li>';
}
echo '</ul>';
wp_reset_postdata();
wp_reset_query();
}
add_action( 'genesis_entry_content', 'ja_category_archive_list' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment