WordPress Date Archive

Create a custom Date Archive using the following snippet.

Place this within your archive.php, or extend it to be an archive-date.php custom template separate from your main archives.

<?php

// date variables - grab the date according to the date archive displayed
$year     = get_the_time('Y'); 
$monthnum = get_the_time('m');
$day      = get_the_time('d');
					
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
					
$args = array(
	'posts_per_page' => 10,
	'post_type' =>'post',
	'orderby' => 'date',
	'order' => 'desc',
	'paged' => $paged,
	'date_query' => array(array( // query the date 
		'year' => $year,
		'month' => $monthnum,
		'date' => $date,
	))
);
			        
			        
query_posts($args); ?>
					
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();  ?>
						
	<div class="entry-content">
		<div class="archive_loop">
			<h2 class="archive_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
			<h4 class="archive_date"><?php echo get_the_date('d/m/Y'); ?></h4>
			<?php the_excerpt(); ?>
		</div>
	</div><!-- .entry-content -->
	<hr/>
					
	<?php endwhile; ?>
<!-- End of the main loop -->
			
<!-- Add the pagination functions here. -->
		
<div id="nav-below">
	<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
	<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
</div>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

Note: header and footer calls for your theme will need to be included.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.