dd

wordpress检查文章是否置顶函数:is_sticky()


【说明】

检查当前文章是否置顶。返回值TRUE 或者 FALSE.

【用法】

<?php is_sticky($post_ID); ?>

【参数】
$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;
}