Last active
March 4, 2016 08:35
-
-
Save samazgor/e894d704a16e024493d8 to your computer and use it in GitHub Desktop.
Display your posts from this exact day in previous years in WordPress
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
/** | |
* | |
* Time Capsule By Sam Azgor | |
* Copy and paste the following code in your theme’s functions.php file | |
* Add this to your template - <?php wp_timehop_sam(); ?> | |
* | |
*/ | |
function wp_timehop() { | |
$today = getdate(); | |
$the_query = new WP_Query( '&monthnum=' . $today['mon'] . '&day=' . $today['mday'] ); | |
if ( $the_query->have_posts() ) : | |
while ( $the_query->have_posts() ) : $the_query->the_post(); ?> | |
<h2><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?> "><?php the_title(); ?></a></h2> | |
<?php the_excerpt(); ?> | |
<?php endwhile; ?> | |
<?php wp_reset_postdata(); ?> | |
<?php else: ?> | |
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> | |
<?php endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment