Identify, add, and delete wordpress-top articles related PHP functions summary _php Example

Source: Internet
Author: User

To judge a sticky article
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 by default is the current article in the loop.

Default value: 0 (current article in loop)

return value

(Boolean) Whether the article is a sticky article.

Example

if (Is_sticky ()) echo//' current article is a sticky article ';
if (Is_sticky) echo//' ID 68 article is a sticky article ';

Other

This function is located at: wp-includes/post.php

Add and remove a function for a sticky article
WordPress default support article top function, you can put important or wonderful articles in the background, so that users priority to see.

In development, you may need to add and remove sticky articles by code. WordPress Top article is the principle of the top article to save the ID to the options table, by modifying the Sticky_posts field can control the top article.

However, WordPress provides two functions that make it easier to add and remove sticky articles, and call functions directly to modify sticky_posts fields.

Stick_post ()

Stick_post () function is used to put an article at the top, example:

Stick_post (68)//Top 68 article
Stick_post (get_the_id ());//The current article in the sticky loop

Unstick_post ()

Unstick_post () and the Stick_post () function are used to remove a top article from the top:

Unstick_post (425); Cancel the article unstick_post with a top ID of 425
(get_the_id ());/Cancel current article in the top loop

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.