Skip to content

Instantly share code, notes, and snippets.

@10h30
Forked from bradonomics/year-archive-template.php
Created October 16, 2018 08:23
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 10h30/2adbb5e1fd1c802e24c6c7a31b59d7ef to your computer and use it in GitHub Desktop.
Save 10h30/2adbb5e1fd1c802e24c6c7a31b59d7ef 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