WordPressのカレンダーをカスタマイズ

折角なのでWordpressのカスタマイズをしてみる。
本当はプラグインでやるべきだケド、それはまた別の機会に。

前からやりたかったのが、カレンダーの土日の色づけ。

calendarでソースをGrepすると、
wp-includes/general-template.phpに処理があることがわかった。
その中のfor文で1日~末日をグルグルまわしているところに、土日それぞれのセルにsaturday,sundayのIDを振る処理を追加。

for ( $day = 1; $day <= $daysinmonth; ++$day ) {

まずは、$weeknumって変数を作って曜日を数値化したものを取得。
次に、if文に分岐を増やして、土曜、日曜分のIDを振ってやる。

$weeknum = calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear)));

if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp'))
&& $thisyear == gmdate('Y', current_time('timestamp')) )
$calendar_output .= '<td id="today">';
// add 2011/08/05 from ----------------------
elseif ($weeknum == 0)
    $calendar_output .= '<td id="sunday">';
elseif ($weeknum == 6)
    $calendar_output .= '<td id="saturday">';
// add 2011/08/05 to ----------------------
else
$calendar_output .= '<td>';

あとは、使用中のthemeフォルダにあるstyle.css#todayあたりに、saturday,sunday用のスタイルを追加しておけばOK。

以上、オシマイ。

w03.gifでけたよ~!

Add a Comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください