To judge a sticky article
the Is_sticky () function is used to determine whether an article is a sticky article.
Usage
Parameters
$post _id
(integer) (optional) The article ID to be judged by default is the current article in the loop.
Default value: 0 (current article in loop)
return value
(Boolean) Whether the article is a sticky article.
Example
if (Is_sticky ()) echo//' current article is a sticky article ';
if (Is_sticky) echo//' ID 68 article is a sticky article ';
Other
This function is located at: wp-includes/post.php
Add and remove a function for a sticky article
WordPress default support article top function, you can put important or wonderful articles in the background, so that users priority to see.
In development, you may need to add and remove sticky articles by code. WordPress Top article is the principle of the top article to save the ID to the options table, by modifying the Sticky_posts field can control the top article.
However, WordPress provides two functions that make it easier to add and remove sticky articles, and call functions directly to modify sticky_posts fields.
Stick_post ()
Stick_post () function is used to put an article at the top, example:
Stick_post (68)//Top 68 article
Stick_post (get_the_id ());//The current article in the sticky loop
Unstick_post ()
Unstick_post () and the Stick_post () function are used to remove a top article from the top:
Unstick_post (425); Cancel the article unstick_post with a top ID of 425
(get_the_id ());/Cancel current article in the top loop