确定帖子是否是粘性的。
原型
is_sticky( int $post_id )
描述
粘性帖子应保留在The Loop的顶部。如果未给出帖子ID,则将使用当前帖子的循环ID。
参数
$post_id
(int)
(Optional)
帖子ID。默认值是全局$ post的ID。
返回值
(bool)
帖子是否有粘性。
源文件
路径:wp-includes/post.php
<?php
...
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;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/is_sticky/