is_date 判断是否日期归档页
只看 is_date 这个函数的名字,很容易误认为是判断是否是时间类型的。
其实,在 WordPress 中,is_date 是用来判断是否是日期归档页的。类似的函数还有:is_year、is_month、is_day。
也想出现在这里?联系我们吧

is_year 对应的链接类似:.../date/2022。
is_month 对应的链接类似:.../date/2022/02。
is_day 对应的链接类似:.../date/2022/02/18。
此函数经常于 wp_get_archives、get_year_link、get_month_link、get_day_link 配合,生成全站的按日期归档的页面 date.php。
用法举例:
if (is_date()) {
if (is_year()) {
echo get_the_time('Y');
} else if (is_month()) {
echo get_the_time('Y-m');
} else if (is_day()) {
echo get_the_time('Y-m-d');
}
}