monthchunks plugin for WordPress
月別アーカイブをコンパクトに表示。
monthchunks plugin for WordPress http://justinsomnia.org/2005/04/monthchunks-howto/
左列真ん中くらいに
Instructions
Download and unzip monthchunks-2.1.zip (v2.1)
ダウンロード後 /wp-content/plugins/ へアップ、有効。
うちのテーマでは <?php wp_get_archives(‘type=monthly’); ?> は使ってない。
/wp-includes/widgets.php
801行目を変更。
/**
* Display archives widget.
*
* @since 2.2.0
*
* @param array $args Widget arguments.
*/
function wp_widget_archives($args) {
extract($args);
$options = get_option('widget_archives');
$c = $options['count'] ? '1' : '0';
$d = $options['dropdown'] ? '1' : '0';
$title = empty($options['title']) ? __('Archives') : apply_filters('widget_title', $options['title']);
echo $before_widget;
echo $before_title . $title . $after_title;
if($d) {
?>
<select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Month')); ?></option> <?php wp_get_archives("type=monthly&format=option&show_post_count=$c"); ?> </select>
<?php
} else {
?>
<ul>
<?php monthchunks("descending"); ?> //変更、オプションのdescendingで新年度が上に表示
</ul>
<?php
}
echo $after_widget;
}
一桁月の前にゼロをつける。
参考先 「月別アーカイブをコンパクトにするプラグイン「monthchunks」」
http://www.wp-guide.net/wpplugin/wphyouji/150.html
/wp-content/plugins/monthchunks-2.1/monthchunks.php
76、97行目変更
function monthchunks($year_order = "ascending", $month_format = "numeric")
{
// get access to wordpress' database object
global $wpdb;
$current_month = "";
$current_year = "";
// get current year/month if current page is monthly archive
if (is_month())
{
$current_month = get_the_time('m'); //変更
$current_year = get_the_time('Y');
}
// set SQL order by sort order
if ($year_order == "descending")
{
$year_order = "DESC";
}
else
{
$year_order = "ASC";
}
// set format for month display
if ($month_format == "alpha")
{
$month_format = "LEFT(DATE_FORMAT(post_date, '%M'), 1)";
}
else
{
$month_format = "DATE_FORMAT(post_date, '%m')"; //変更
}

最終は
参考ページ
monthchunksの表記を日本語にしてみた http://blog.open-arms.biz/200805/06422.php
// start the list item displaying the year
$year_= $year ."年";
print "<li><strong>$year_</strong><br />\n";
// loop through each month, creating a link
// followed by a single space
$month_count = count($months);
$i = 0;
foreach($months as $month)
{
// display the current month in bold without a link
if ($year == $current_year && $month->post_month == $current_month)
{
$month_ = $month->display_month . "月";
print "<strong title='$month->post_month_name $year'>$month_</strong>";
}
else
{
$month_ = $month->display_month . "月";
print "<a href='" . get_month_link($year, $month->post_month) . "' title='$month->post_month_name $year'>" . $month_ . "</a>";
}
if ($i < $month_count-1)
{
print " \n";
}
$i++;
}
//end the year list item
print "</li>\n\n";
}
}
?>
Popularity: 1% [?]
