sticky_class()
云策文档标注
概述
sticky_class() 是一个已弃用的 WordPress 函数,用于在文章是置顶时输出 "sticky" CSS 类。自 WordPress 3.5.0 起,建议使用 post_class() 替代。
关键要点
- sticky_class() 函数检查指定文章是否为置顶,如果是则输出 "sticky" 类名。
- 该函数在 WordPress 3.5.0 版本中被弃用,推荐使用 post_class() 函数来实现相同功能。
- 函数接受一个可选的 $post_id 参数,默认为 null,用于指定文章 ID。
- 内部调用 is_sticky() 判断置顶状态,并使用 _deprecated_function() 标记弃用。
注意事项
由于 sticky_class() 已弃用,新开发中应避免使用,转而使用 post_class() 以确保兼容性和最佳实践。
原文内容
Display “sticky” CSS class, if a post is sticky.
Description
See also
Parameters
$post_idintoptional-
An optional post ID.
Default:
null
Source
function sticky_class( $post_id = null ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'post_class()' );
if ( is_sticky( $post_id ) )
echo ' sticky';
}
Changelog
| Version | Description |
|---|---|
| 3.5.0 | Deprecated. Use post_class() |
| 2.7.0 | Introduced. |