What are the PHP functions for judging, adding, and deleting WordPress top articles
This article is about judging, adding, and removing PHP functions from WordPress top articles. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Judge the article at the top
The is_sticky () function is used to determine whether an article is the top article.
Usage
Is_sticky ($post_id)
Parameters.
$post_id
(integer) (optional) the article ID to be judged is the current article in the loop by default.
Default value: 0 (current article in the loop)
Return value
(Boolean) whether the article is at the top.
Examples
If (is_sticky ()) echo / / 'current article is top article'; if (is_sticky (68)) echo / / 'articles with ID of 68 are top articles'
Other
This function is located at: wp-includes/post.php
Add and remove functions for top articles
WordPress supports articles at the top by default, and you can put important or wonderful articles at the top in the background for users to see first.
In development, you may need to add and remove top articles through code. The principle of the WordPress top article is to store the ID of the top article in the options table, and you can control the top article by modifying the sticky_posts field.
However, WordPress provides two functions that make it easier to add and remove top articles, and directly call the function to modify the sticky_posts field.
Stick_post ()
The stick_post () function is used to top an article, for example:
Stick_post (68); / / articles with an ID of 68 stick_post (get_the_ID ()); / / current articles in the top loop
Unstick_post ()
The unstick_post () and stick_post () functions, in contrast, are used to untop a top article:
Unstick_post (425); / / unset the article unstick_post (get_the_ID ()) with the top ID of 425; / / cancel the current article in the top loop. Thank you for reading! This is the end of this article on "judging, adding and deleting PHP functions of WordPress Top articles". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!