Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_calendar_filter( $input ) {
- global $year, $monthnum, $m, $wp_locale;
- $output = $input;
- // 現在の年月を取得
- $ts = current_time('timestamp');
- $currentyear = (int) gmdate('Y', $ts);
- $currentmonth = gmdate('m', $ts);
- // グローバル変数から現在のページの年月を取得
- if ( $year && $monthnum ) {
- $thisyear = (int) $year;
- $thismonth = (int) sprintf( '%02s', $monthnum );
- } elseif ( isset($m) && is_numeric($m) && strlen($m) > 3 ) {
- $thisyear = (int) substr($m, 0, 4);
- if ( strlen($m) < 6 )
- $thismonth = 1;
- else
- $thismonth = (int) substr($m, 4, 2);
- }
- // 年月のチェック
- if ( $thisyear > 1970 && $thismonth > 0 && $thismonth < 13 ) {
- $thisyear = $thisyear;
- $thismonth = sprintf( '%02s', $thismonth );
- } else { // 不正なら現在の年月を使用
- $thisyear = $currentyear;
- $thismonth = $currentmonth;
- }
- // 前月・翌月を取得
- if ( $thismonth === '01' ) {
- $prev = array($thisyear - 1, 12);
- $next = array($thisyear, 2);
- } elseif ( $thismonth === '12' ) {
- $prev = array($thisyear, 11);
- $next = array($thisyear + 1, 1);
- } else {
- $prev = array($thisyear, (int) $thismonth - 1 );
- $next = array($thisyear, (int) $thismonth + 1 );
- }
- // 前月を書き換え
- if ( ($currentyear * 100 + $currentmonth) >= ($prev[0] * 100 + $prev[1]) ) { // 未来でなければ
- $prev_pattern = '/<td colspan="3" id="prev"[^>]*>.+?<\/td>/';
- $prev_replace = '<td colspan="3" id="prev"><a href="'.get_month_link($prev[0], $prev[1]).'">« '
- .$wp_locale->get_month_abbrev($wp_locale->get_month($prev[1])).'</a></td>';
- $output = preg_replace( $prev_pattern, $prev_replace, $output );
- }
- // 翌月を書き換え
- if ( ($currentyear * 100 + $currentmonth) >= ($next[0] * 100 + $next[1]) ) { // 未来でなければ
- $next_pattern = '/<td colspan="3" id="next"[^>]*>.+?<\/td>/';
- $next_replace = '<td colspan="3" id="next"><a href="'.get_month_link($next[0], $next[1]).'">'
- .$wp_locale->get_month_abbrev($wp_locale->get_month($next[1])).' »</a></td>';
- $output = preg_replace( $next_pattern, $next_replace, $output );
- }
- return $output;
- }
- add_filter( 'get_calendar', 'get_calendar_filter' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement