The parameters and usage of is_sticky () in wordpress to judge whether the article is at the top or not.
This article mainly introduces the wordpress is_sticky () how to judge whether the article is the top of the parameters and usage, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
[description]
Check whether the current article is at the top. Returns a value of TRUE or FALSE.
[usage]
The code is as follows:
[parameters]
$post_ID
(string) (optional) Article ID
Default: None
Return value
(boolean)
True, or false.
[example]
The code is as follows:
Is_sticky (); / / any top article is displayed.
Is_sticky ('17'); / / when articles with an ID of 17 are displayed.
[source file]
Is_sticky () is located in wp-includes/post.php.
PHP Code copies content to the clipboard
/ * 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;}
Here are some examples:
Is_sticky (10) is to determine whether an article with a $post_id of 10 is a top article, not a top article with a post_id of 10 in all top articles. The reason why there is a wrong understanding of the latter is that I read the official introduction of the is_sticky ($post_id) method in French. In fact, after a close study, "all the articles with a post_id of 10 in the top article" is also superfluous. Directly $post- > id==10 or get_the_id () = 10 to determine whether the current article $post_id is equal to 10!
I would also like to thank brother tiandi in Youchuan for reminding me that there is no problem of "invalid parameters in is_sticky ($post_ID)" and correcting his misunderstanding of the wordpress is_sticky ($post_id) method.
Thank you for reading this article carefully. I hope the article "how to judge the parameters and usage of is_sticky () in wordpress" shared by the editor is helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!