返回介绍

is_sticky()

发布于 2017-09-11 01:27:23 字数 2943 浏览 1062 评论 0 收藏 0

is_sticky( int $post_id )

Check if post is sticky.


description

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.


参数

$post_id

(int) (Optional) Post ID. Default is ID of the global $post.


返回值

(bool) Whether post is sticky.


源代码

File: wp-includes/post.php

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

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-includes/functions.php: absint()
  • wp-includes/option.php: get_option()
  • wp-includes/post-template.php: get_the_ID()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_item_for_database()
  • wp-admin/includes/export.php: export_wp()
  • wp-admin/includes/template.php: _post_states()
  • wp-admin/includes/template.php: get_inline_data()
  • wp-admin/includes/meta-boxes.php: post_submit_meta_box()
  • wp-includes/deprecated.php: sticky_class()
  • wp-includes/post-template.php: get_post_class()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_getPost()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_getRecentPosts()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_prepare_post()
  • Show 6 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文