Skip to content

Instantly share code, notes, and snippets.

@bradonomics
Last active January 23, 2021 18:26
Show Gist options
  • Save bradonomics/2e51a419c46617a2fcac to your computer and use it in GitHub Desktop.
Save bradonomics/2e51a419c46617a2fcac to your computer and use it in GitHub Desktop.
Genesis Page Template displaying posts by year. Inspired by Alex Sexton's blog archives: https://alexsexton.com/blog/archives/ and built using code modified from Joe Mar Aparecio: http://www.joemaraparecio.com/customizing-genesis-archive-template-display-posts-month/
<?php
/**
*
* Custom Blog Loop for Bradonomics.
*
* Template Name: Bradonomics Blog
*
*/
//* Remove standard post content output
remove_action( 'genesis_loop', 'genesis_do_loop' );
//* Add Page Title and Content
add_action( 'genesis_loop', 'genesis_standard_loop', 5 );
//* Add custom archive output
add_action( 'genesis_loop', 'bradonomics_blog_template' );
function bradonomics_blog_template() {
$post_items = new WP_Query( array(
'post_type'=> 'post',
'showposts' => '-1',
'order' => 'DESC',
'orderby' => 'date'
));
$set_year = '';
while( $post_items->have_posts()) : $post_items->the_post();
if( $set_year == '' ){
$set_year = get_the_date(Y);
echo '<div class="wrap"><div class="group-year"><p>' . get_the_date(Y) . '</p>';
}else{
if( $set_year != get_the_date(Y) ){
echo '</div>';
echo '<div class="group-year"><p>' .get_the_date(Y) . '</p>';
$set_year = get_the_date(Y);
}
}
echo '<article>';
echo '<h3><a href="'.get_the_permalink().'">'.get_the_title().'</a></h3>';
echo '<time><span class="month">' . get_the_date(M) . '</span> <span class="day">' . get_the_date(j) . '</span> <span class="year">' . get_the_date(Y) . '</span></time>';
echo '</article>';
endwhile;
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment