Functions used in WordPress for obtaining information about articles and classifying links

Source: Internet
Author: User
Get_post () (Get an article)
The Get_post () function can query the information of an article based on its ID, and can also return the current article in the loop.

Usage

Get_post ($post, $output, $filter);

Parameters

$id

(Integer | Object) (optional) Article ID or article object, if blank, is automatically set to the current article.

Default value: null (current article)

$output

(string) (optional) Returns the form of the result, optionally:

    • Object: Returns an Article object
    • Array_a: Returns an array with a key value
    • Array_n: Returns an array without a key value
    • Default value: OBJECT

$filter

(string) (optional) Article information filtering method. Refer to the Sanitize_post_field () function specifically.

Default value: Row

return value

(Object | null | Array) Returns the article object, array, or null.

Example

Get an article with an ID of 7 and print out its title:

$post _7 = get_post (7); $title = $post _7->post_title;

Get the article with ID 7 (in array form) and print out its caption:

$post _7 = get_post (7, array_a); $title = $post _7[' post_title '];

Other

This function is located in: wp-includes/post.php and wp-includes/class-wp-atom-server.php


Get category Links
In the development of WordPress, often need to get the link of the classification.

If you know the classification ID, you just need to use the Get_category_link () function to get it directly.

But in the actual situation may only know a little bit of classified information, below I introduce a variety of classification information to obtain classification links method.

Get category links by category ID

It is easier to get the classification link by ID, directly using the Get_category_link () function.

Echo Get_category_link (23);

Get category links by category Alias

To get the classification link according to the classification alias need one more step, first use the Get_category_by_slug () function to obtain the classification according to the alias, and then get the classification link.

Echo Get_category_link (Get_category_by_slug (' tips '));

Get category links by category name

The classification link is obtained according to the classification name, and the principle is similar to that of classification aliases, which is to obtain the classification first and then get the link.

Echo Get_category_link (get_cat_id (' WordPress tutorial '));

The above describes the WordPress in the use of information and classification links to use the function, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.