Method parameters and usage of is_sticky () top post in wordpress

Source: Internet
Author: User

[Description]

Check whether the current article is topped. Returns TRUE or FALSE.

[Usage]

<? Php is_sticky ($ post_ID);?>

[Parameters]

$ Post_ID

(String) (optional) Article ID
Default value: None
Return value
(Boolean)
True, or false.

[Example]


Is_sticky ();

// Any top post is displayed.

Is_sticky ('17 ');

// When the ID is 17, the article is displayed.

[Source file]

Is_sticky () is located in wp-receivdes/post. php.

/**
* Check if post is sticky.
 *
* Sticky posts shoshould 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;
}

The following is an example:

Is_sticky (10) is used to determine whether an article with $ post_id 10 is a top article, rather than a top article with post_id 10 in all top articles. The reason for the latter's misunderstanding is that I read the official introduction to the is_sticky ($ post_id) method usage document, which is rather vague, this judgment is redundant, and $ post-> id = 10 or get_the_id () = 10 determine whether the current article $ post_id is equal to 10!


Here, I would like to thank tiandi in my friend chain for reminding me that the parameter "is_sticky ($ post_ID) is invalid" does not exist in my message on this site. I want to correct my opinion on wordpress is_sticky ($ post_id) method error.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.