年月別アーカイブを作っているのですが、下記のプログラムに表示される
月の0を消したいのと1月から12月まで表示し、その中で記事が投稿されている月だけをクリックできるようにしたいのですがやり方がわかりません、わかる方教えてください!
現在表示
2017
01 02 07 09 10
最終的に表示したい形
2017
1 2 3 4 5 6 7 8 9 10 11 12
<?php $archives_year = wp_get_archives('post_type=blog&type=yearly&show_post_count=0&format="option"&echo=0'); // 年毎に分割 $archives_year_array = split("\n", $archives_year); foreach ($archives_year_array as $archive_year_tag) { // 要素ごとに分解 preg_match("/(<a.*?>)(\d{4})(<.*?>)/", $archive_year_tag, $elements); $archives_year_map[$elements[2]] = $archive_year_tag; } // 月別アーカイブ取得 $archives_month = wp_get_archives('post_type=blog&type=monthly&show_post_count=1&format="option"&echo=0'); // 月毎に分割 $archives_month_array = explode("\n", $archives_month); // Buffer output ob_start(); ?> <ul class="clearfix archives"> <?php $before_year = ""; foreach ($archives_month_array as $archive_month_tag) { if ($archive_month_tag == "") { // 最後に空白のゴミが入るのでスキップ break; } // 要素毎に分解 preg_match_all("/<.*?>/", $archive_month_tag, $tags); preg_match("/(\d{4})年/", $archive_month_tag, $year); preg_match("/(\d+)月/", $archive_month_tag, $month); preg_match("/((\d+))/", $archive_month_tag, $count); // 年が変わったら年を出力 if ($year[1] != $before_year) { printf("<p>%s</p>\n", $archives_year_map[$year[1]]); $before_year = $year[1]; } printf("<li>%s%02d</a></li>\n", $tags[0][0], $month[1], $count[1]); } ?> </ul>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。