Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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