Judge, add, and delete related PHP function summary_php instance for WordPress top posts

Source: Internet
Author: User
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 ()

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.