the_weekday()
云策文档标注
概述
the_weekday() 是一个 WordPress 模板函数,用于显示当前循环中文章的本地化星期几。它基于文章的发布时间,通过 WP_Locale 类获取翻译后的星期名称。
关键要点
- 函数功能:输出文章的本地化星期几,基于文章的发布时间(使用 get_post_time() 获取)。
- 核心依赖:使用 WP_Locale::get_weekday() 获取翻译后的星期名称,支持多语言本地化。
- Hook 支持:通过 apply_filters('the_weekday', $the_weekday) 允许开发者过滤输出的星期字符串。
- 相关函数:涉及 get_post()、get_post_time()、apply_filters() 等核心 WordPress 函数。
- 版本历史:自 WordPress 0.71 版本引入,是一个基础且稳定的模板标签。
原文内容
Displays the localized weekday for the post.
Source
function the_weekday() {
global $wp_locale;
$post = get_post();
if ( ! $post ) {
return;
}
$the_weekday = $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
/**
* Filters the localized weekday of the post, for display.
*
* @since 0.71
*
* @param string $the_weekday
*/
echo apply_filters( 'the_weekday', $the_weekday );
}
Hooks
- apply_filters( ‘the_weekday’, string $the_weekday )
-
Filters the localized weekday of the post, for display.
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |
Skip to note 2 content
Codex
Displays the day of the week on which the currently looped posts have been published.
<p>This was posted on a .</p>