Skip to content

Instantly share code, notes, and snippets.

@braddalton
Last active November 3, 2017 14:22
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 braddalton/8896e1a3bc2d4249049cde448208a18d to your computer and use it in GitHub Desktop.
Save braddalton/8896e1a3bc2d4249049cde448208a18d to your computer and use it in GitHub Desktop.
Genesis Template To Display Posts by Year https://wp.me/p1lTu0-hbw
<?php
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'yearly_posts' );
/**
* @author Brad Dalton
* @link https://wpsites.net/web-design/genesis-template-to-display-posts-by-year/
*/
function yearly_posts() {
$args = array(
'posts_per_page' => '3',
'date_query' => array(
array(
'year' => 2016
),
),
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
wp_reset_postdata();
} else {
}
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment