Summary of relevant PHP functions for judging, adding and removing WordPress sticky articles

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

  • 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.