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

目录

描述

This Conditional Tag checks if the current post is a Sticky Post meaning the "Stick this post to the front page" check box has been checked for the post. This is a boolean function, meaning it returns either TRUE or FALSE.

is_sticky() 描述

用法

<?php is_sticky($post_ID); ?>

is_sticky() 用法

参数

$post_ID

(string) (可选) The post ID

默认值: None

is_sticky() 参数

返回值

(boolean) 

True on success, false on failure.

is_sticky() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
is_sticky();
// When any Sticky Post page is being displayed.

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

is_sticky() 示例

历史

添加于 版本: 2.7.0

is_sticky() 历史

源文件

is_sticky() 函数的代码位于 wp-includes/post.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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;
}

is_sticky() 源文件

相关