is_new_day()
云策文档标注
概述
is_new_day() 是一个 WordPress 主题函数,用于在循环中判断当前文章发布日期是否与前一篇不同,常用于日期分隔显示。
关键要点
- 函数返回整数:1 表示新的一天,0 表示不是新的一天
- 基于全局变量 $currentday 和 $previousday 进行比较
- 主要用于主题开发,与 the_date() 等函数配合使用
代码示例
function is_new_day() {
global $currentday, $previousday;
if ( $currentday !== $previousday ) {
return 1;
} else {
return 0;
}
}注意事项
- 函数自 WordPress 0.71 版本引入,属于核心功能
- 建议参考主题开发者手册中的条件标签文章了解更多类似函数
原文内容
Determines whether the publish date of the current post in the loop is different from the publish date of the previous post in the loop.
Description
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Source
function is_new_day() {
global $currentday, $previousday;
if ( $currentday !== $previousday ) {
return 1;
} else {
return 0;
}
}
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |