Last active
November 3, 2017 14:22
-
-
Save braddalton/8896e1a3bc2d4249049cde448208a18d to your computer and use it in GitHub Desktop.
Genesis Template To Display Posts by Year https://wp.me/p1lTu0-hbw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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