Last active
August 29, 2015 13:59
-
-
Save manchumahara/10569985 to your computer and use it in GitHub Desktop.
for style use this ul.plainyearbasedtimelinelist{ border-left: 4px solid #E5E5E5 !important; margin-left: 20px; padding-left: 30px; }
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 | |
$last_changed = wp_cache_get( 'last_changed', 'posts' ); | |
if ( ! $last_changed ) { | |
$last_changed = microtime(); | |
wp_cache_set( 'last_changed', $last_changed, 'posts' ); | |
} | |
global $wpdb; | |
$limit = ''; | |
$order = 'DESC'; | |
$where = "WHERE post_type = 'post' AND post_status = 'publish'"; | |
$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit"; | |
$key = md5( $query ); | |
$key = "plainyearbasedtimeline:$key:$last_changed"; | |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) { | |
$results = $wpdb->get_results( $query ); | |
wp_cache_set( $key, $results, 'posts' ); | |
} | |
//$output = ''; | |
if ( $results ) { | |
$afterafter = $after; | |
foreach ( (array) $results as $result) { | |
$url = get_year_link($result->year); | |
$text = sprintf('%d', $result->year); | |
// if ($show_post_count) | |
// $after = ' ('.$result->posts.')' . $afterafter; | |
echo '<p>'. get_archives_link($url, $text, $format, $before, $after).'</p>'; | |
// The Query | |
$args = array( | |
'post_type' => 'post', | |
'post_status' =>'publish', | |
'posts_per_page' => -1, | |
'year' => intval($result->year) | |
); | |
$yearqkey = 'plainyearbasedtimelinepost'.$result->year; | |
//if ( ! $the_query = wp_cache_get( $yearqkey, 'posts' ) ) { | |
$the_query = new WP_Query( $args ); | |
// wp_cache_set( $yearqkey, $the_query, 'posts' ); | |
//} | |
// The Loop | |
if ( $the_query->have_posts() ) { | |
echo '<ul class="unstyled plainyearbasedtimelinelist">'; | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); | |
echo '<li> <time datetime="'.get_the_time('Y-m-j').'" >'.get_the_date().'</time> <a href="'.get_permalink().'">' . get_the_title() . '</a></li>'; | |
} | |
echo '</ul>'; | |
} else { | |
// no posts found | |
} | |
/* Restore original Post Data */ | |
//if ( ! $the_query = wp_cache_get( $yearqkey, 'posts' ) ) { | |
wp_reset_postdata(); | |
//} | |
} | |
//echo $output; | |
} | |
?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment