Last active
February 4, 2017 02:00
-
-
Save kjbrum/d7f3a5eb5d196d6a5fce to your computer and use it in GitHub Desktop.
Display the monthly archive links for a specific year.
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 | |
/** | |
* Display the archive links for a single year. | |
* | |
* @param integer $year The year you would like to display the archives for | |
* @param string $menu_class Class to add to the ul tag | |
* @return void | |
*/ | |
function wp_single_year_monthly_archives($year=null, $menu_class=null) { | |
if($year == null) { | |
$year = date('Y'); | |
} | |
$months = range(1,12); | |
$monthly_posts = array(); | |
foreach ( $months as $month ) { | |
$posts_for_month = get_posts(array( | |
'year' => $year, | |
'monthnum' => $month | |
)); | |
$monthly_posts[$month] = $posts_for_month; | |
} | |
$classes = ($menu_class)?' class="'.$menu_class.'"':''; | |
echo '<ul'.$classes.'>'; | |
foreach ( $monthly_posts as $month => $posts ) { | |
$time = mktime(0, 0, 0, $month); | |
$month_name = strftime("%B", $time); | |
if ($posts) { | |
echo '<li><a href="' .get_month_link($year, $month). '">' .$month_name. '</a></li>'; | |
} | |
} | |
echo '</ul>'; | |
wp_reset_query(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment