1. 首页
  2. WordPress 函数手册

is_sticky()

is_sticky( int $post_id )

确定帖子是否有粘性。
Determines whether a post is sticky.

目录锚点:#说明#参数#返回#源码#笔记


说明(Description)

粘帖应该保持在圈的顶部。如果没有给出post ID,那么将使用当前post的循环ID。

有关此主题函数和类似主题函数的更多信息,请参阅主题开发人员手册中的条件标记文章。


参数(Parameters)

参数 类型 必填 说明
$post_id (int) 可选 Post ID。默认值是全局$Post的ID。

返回(Return)

(bool)post是否有粘性。


源码(Source)

/**
 * 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. Default is ID of the global $post.
 * @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;
}
更新版本 源码位置 使用 被使用
2.7.0 wp-includes/post.php:2278 11 5

笔记(Notes)

基本示例

is_sticky() 为WP2原创文章,链接:https://www.wp2.cn/functions/is_sticky/