こんな感じで特定カテゴリーの年別・月別アーカイブの美しい一覧表を作ってみたのでメモ。
まず以下の記事が大変参考になったのであります。
[WordPress] wp_get_archivesをカスタマイズし年と月が対応したテーブルを作る
上記で紹介されているソースに、
wp_get_archives(‘cat=15&・・・
のようにカテゴリーを指定できたらステキなわけです。
でもWordPressの標準機能ではこれは許されないことです。
そこで登場するのが Archives for a category というプラグイン。
これをインストール&有効化するだけで、先ほどのカテゴリー指定が出来てしまうという優れもので利用者も多いようです。(しばらくプラグイン自体更新していないようなのでちと怖いけど。。)
[WordPress]カテゴリー別に月別アーカイブを表示できるプラグイン「Archives for a category」
そんなこんなで出来たソースはこんな感じ。
=$firstyear;$year-- ){ $tbody .= "
"; } echo $tbody; ?> {$year}年 "; $tr = ''; for( $month=12;$month>0;$month-- ){ if( !preg_match( "/年".$month."月/u", $arr[$cnt] ) ){ $tr = "{$month}月 " . $tr; }else{ $tr = "".preg_replace("/\d{4}年/u", "",trim($arr[$cnt]))." " . $tr; $cnt++; } } $tbody .= $tr . "
CSSはこんな感じ。
#words{
width:100%
margin:5px auto;
font-size:75%;
border:#6699ff 1.5px solid;
}
#words tr{
border-bottom:#6699ff 1px solid;
}
#words tr:last-child{
border:none
}
#words th{
width:8%!important;
padding:5px 10px;
display:table-cell;
border-right:#6699ff 1px solid;
text-align: left;
}
#words td{
width:7%!important;
padding:5px 10px;
display:table-cell;
text-align: left;
}
以上、「Archives for a category」に替わる良いプラグインがあったら、だれか教えてー。
