WordPress函数is_sticky()判断当前页面类型是否为置顶文章

描述:

判断当前页面类型是否为置顶文章

用法:

<?php is_sticky($post_ID); ?>

参数:

$post_ID

(string) (可选) 文章ID

默认值: None

示例:

is_sticky();
// When any Sticky Post page is being displayed.

is_sticky('17');
// When Sticky Post 17 (ID) is being displayed.

源文件:

/**
 * 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;
}