Judging pinned articles
The Is_sticky () function is used to determine whether an article is a sticky article.
Usage
Is_sticky ($post _id);
Parameters
$post _id
(integer) (optional) The article ID to be judged, which by default is the current article in the loop.
Default value: 0 (the current article in the loop)
return value
(Boolean) Whether the article is a pinned article.
Example
if (Is_sticky ()) echo//' current article is a sticky article '; if (is_sticky) echo//' ID 68 article is a top article ';
Other
This function is located at: wp-includes/post.php
Add and remove a function from a pinned article
WordPress default support article pinned features, you can put important or wonderful articles in the background top, let users first see.
In development, you may need to add and remove pinned articles through code. WordPress Sticky article principle is to put the ID of the top article to the options table, by modifying the Sticky_posts field to control the pinned article.
However, WordPress provides two functions that make it easier to add and remove pinned articles, and directly invoke functions to modify the Sticky_posts field.
Stick_post ()
The Stick_post () function is used to pin an article, for example:
Stick_post (68);//The article Stick_post (get_the_id ()) with the top ID of 68, or the current article in the sticky loop
Unstick_post ()
The Unstick_post () and the Stick_post () function, instead, are used to unpin a pinned article:
Unstick_post (425);//Cancel the article Unstick_post (get_the_id ()) with the top ID of 425, or cancel the current article in the sticky loop
The above describes the judgment, add and delete wordpress top article of the relevant PHP function summary, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.