This article mainly introduces the PHP function summary for judging, adding, and deleting WordPress top posts. For more information, see
Determine top posts
The is_sticky () function is used to determine whether an article is pinned.
Usage
is_sticky( $post_id );
Parameters
$ Post_id
(Integer) (optional) ID of the article to be judged. The default value is the current article in the loop.
Default Value: 0 (current article in the loop)
Return Value
(Boolean) whether the article is the top article.
Example
If (is_sticky () echo // 'current article is the top topic '; if (is_sticky (68) echo // 'Article with ID 68 is the top topic ';
Others
This function is located in: wp-uplodes/post. php
Add and remove top posts
By default, WordPress supports the article top function. You can pin important or brilliant articles on the background to give users a higher priority.
During development, you may need to add and remove top articles through code. The principle of WordPress pin-to-top article is to store the ID of the pin-to-top article in the options table, and control the pin-to-top article by modifying the sticky_posts field.
However, WordPress provides two functions to easily add and remove the sticky_posts field by directly calling the function.
Stick_post ()
The stick_post () function is used to top an article. Example:
Stick_post (68); // stick_post (get_the_ID () of the article with the top ID 68; // the current article in the top loop
Unstick_post ()
The unstick_post () function is opposite to the stick_post () function to unpin a top article:
Unstick_post (425); // unstick_post (get_the_ID () of the article whose top ID is 425; // unstick_post (get_the_ID ()