【说明】
检查当前文章是否置顶。返回值TRUE 或者 FALSE.
【用法】
【参数】
$post_ID
(string) (optional) 文章 ID
默认: None
返回值
(boolean)
True,或 false.
【示例】
is_sticky();
// 任意置顶文章被显示.
is_sticky('17');
// 当ID为17的文章被显示.
【源文件】
is_sticky() 位于 wp-includes/post.php.
/**
* Check if post is sticky.
*
* Sticky posts should remain at the top of The Loop. If the post ID is not
* given, then The Loop ID for the current post will be used.
*
* @since 2.7.0
*
* @param int $post_id Optional. Post ID.
* @return bool Whether post is sticky.
*/
function is_sticky( $post_id = 0 ) {
$post_id = absint( $post_id );
if ( ! $post_id )
$post_id = get_the_ID();
$stickies = get_option( 'sticky_posts' );
if ( ! is_array( $stickies ) )
return false;
if ( in_array( $post_id, $stickies ) )
return true;
return false;
}
这里要举例说明的是:
is_sticky(10) 是判断 $post_id为 10的文章是否是置顶文章,而不是说所有置顶文章中post_id为 10的置顶文章。之所以会有后者错误的理解,也是自己看了官方对于 is_sticky($post_id)方法用法文档比较模糊的介绍,其实细究起来,“所有置顶文章中post_id为 10的置顶文章” 这种判断也是多余的,直接 $post->id==10 或 get_the_id()==10 判断当前文章$post_id是否等于10 就好了!
这里还得感谢下友链中的tiandi兄在本站中留言中提醒说不存在“is_sticky($post_ID)中参数失效”的问题,指正自己对wordpress is_sticky($post_id)方法的错误理解。
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级