wpseek.com
WordPress开发者和主题制作者的搜索引擎



is_sticky › WordPress Function

Since2.7.0
已弃用n/a
is_sticky ( $post_id = 0 )
参数:
  • (int) $post_id Optional. Post ID. Default is the ID of the global `$post`.
    Required: No
    默认:
返回:
  • (bool) Whether post is sticky.
定义在:
文档:

Determines whether a 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. For more information on this and similar theme functions, check out the {@link Conditional Tags} article in the Theme Developer Handbook.


源码

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 ) ) {
		$stickies  = array_map( 'intval', $stickies );
		$is_sticky = in_array( $post_id, $stickies, true );
	} else {
		$is_sticky = false;
	}

	/**
	 * Filters whether a post is sticky.
	 *
	 * @since 5.3.0
	 *
	 * @param bool $is_sticky Whether a post is sticky.
	 * @param int  $post_id   Post ID.
	 */
	return apply_filters( 'is_sticky', $is_sticky, $post_id );
}