我想以不同于月度/年度档案的方式显示每日档案。如何检查归档模板是否用于每日归档而不是每月/每年归档?
年、月、日档案的不同显示
1 个回复
最合适的回答,由SO网友:goldenapples 整理而成
Conditional tags FTW。
- is_month() : 当前查看每月存档is_day() : 当前查看单日存档is_year() : 当前查看年度存档is_time() : 当前正在查看基于时间的存档(每小时、每分钟甚至每秒钟)
因此,要测试这些条件中的每一种,请在archive.php (或用于存档页面的任何模板):
// Check what posts were returned in order to find what date the archive is for
global $posts;
$archivedate = strtotime( $posts[0]->post_date);
if (is_day()) {
echo "Daily archive: ".date(\'m/d/Y\', $archivedate);
} else if (is_month()) {
echo "Monthly archive: ".date(\'F Y\', $archivedate);
} else if (is_year()) {
echo "Yearly archive: ".date(\'Y\', $archivedate);
}
结束