WordPress – 年別アーカイブのURLを確認する
年別アーカイブのURLは管理画面でのパーマリンク構造設定でことなりますがカスタム構造でない限り下記のURLでアクセスできるかと思います。
| パーマリンク構造 | URL | 
|---|---|
| 基本 | http://sample-wordpress/?m=2022http://sample-wordpress/?m=202211http://sample-wordpress/?m=20221101 | 
| 日付と投稿名 | http://sample-wordpress/2022/ | 
| 月と投稿名 | http://sample-wordpress/2022/ | 
| 数字ベース | http://sample-wordpress/archives/date/2022/ | 
| 投稿名 | http://sample-wordpress/2022/11/ | 
年別アーカイブのURLを取得する
年別アーカイブのパスが確認できURLを取得したいのであればテンプレートタグget_year_link()get_month_link() / get_day_link()でURLを取得することができます。例えば記事ページなどで更新日を表示させ年別アーカイブへリンクを与えたいのであれば下記のコードで実現可能です。
それぞれパラメータが存在するのでないとエラーになるので注意が必要です。パラメータは''やfalseでも年月日を取得します。
年別アーカイブ
<time itemprop="datePublished" datetime="<?php echo the_modified_date('Y-m-d'); ?>"><a href="<?php echo get_yeaer_link($year);?>"><?php echo the_modified_date('Y/m/d'); ?></a></time>月別アーカイブ
<time itemprop="datePublished" datetime="<?php echo the_modified_date('Y-m-d'); ?>"><a href="<?php echo get_month_link($year, $month);?>"><?php echo the_modified_date('Y/m/d'); ?></a></time>日別アーカイブ
<time itemprop="datePublished" datetime="<?php echo the_modified_date('Y-m-d'); ?>"><a href="<?php echo get_day_link($year, $month, $day);?>"><?php echo the_modified_date('Y/m/d'); ?></a></time>