Created
July 15, 2014 18:40
-
-
Save drrobotnik/7b5d30407e2ddbb20a28 to your computer and use it in GitHub Desktop.
annual archive
This file contains hidden or 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 get_header(); ?> | |
<div class="sub-section"><?php | |
get_template_part( 'layout', 'gallery' ); | |
get_template_part( 'layout', 'sub-menu' ); | |
?></div> | |
<div id="primary" class="content-area site-archives"> | |
<div id="content" class="site-content" role="main"> | |
<?php | |
$output = ''; | |
$r = array( | |
'type' => 'monthly', 'limit' => '', | |
'format' => 'html', 'before' => '', | |
'after' => '', 'show_post_count' => false, | |
'echo' => 1, 'order' => 'ASC', | |
); | |
extract( $r, EXTR_SKIP ); | |
$where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r ); | |
$join = apply_filters( 'getarchives_join', '', $r ); | |
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit"; | |
$key = md5($query); | |
$cache = wp_cache_get( 'cv_get_archives' , 'general'); | |
if ( !isset( $cache[ $key ] ) ) { | |
$arcresults = $wpdb->get_results($query); | |
$cache[ $key ] = $arcresults; | |
wp_cache_set( 'cv_get_archives', $cache, 'general' ); | |
} else { | |
$arcresults = $cache[ $key ]; | |
} | |
if ( $arcresults ) { | |
$afterafter = $after; | |
$beforebefore = ''; | |
$sorted = array(); | |
foreach ( (array) $arcresults as $arcresult ) { | |
$url = get_month_link( $arcresult->year, $arcresult->month ); | |
$beforebefore = $arcresult->year; | |
/* translators: 1: month name, 2: 4-digit year */ | |
$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year); | |
$after = ' ('.$arcresult->posts.')' . $afterafter; | |
if(!isset($sorted[$arcresult->year])) | |
$sorted[$arcresult->year] = ''; | |
$sorted[$arcresult->year] .= get_archives_link($url, $text, $format, $before, $after); | |
} | |
} | |
foreach($sorted as $year => $value){ | |
$output .= '<h3>'.$year.'</h3>'; | |
$output .= '<ul class="arc-list clearfix" id="yearly-archive">'; | |
$output .= $value; | |
$output .= '</ul>'; | |
} | |
echo $output; | |
?> | |
</ul> | |
</div> | |
</div> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment