function usage _php tips for getting article information and classification links in WordPress

Source: Internet
Author: User

Get_post () (Get an article)
the Get_post () function can query the information of an article based on the ID, and return the current article in the loop.

Usage

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

Parameters

$id

(Integer | Object) (optional) The article ID or article object, which is automatically set to the current article if it is empty.

Default value: null (current article)

$output

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

    • Object: Returns an article objects
    • Array_a: Returns an array with key values
    • Array_n: Returns an array with no key values
    • Default value: OBJECT

$filter

(optional) Article information filtering method. Specific reference Sanitize_post_field () function.

Default value: Row

return value

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

Example

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

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

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

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

Other

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


Get category Links
in WordPress development, often need to get the classification of links.

Knowing the category ID only needs to be obtained directly using the Get_category_link () function.

But in the actual situation may only know a little classification information, below I introduce a variety of classification information to get the classification of the link method.

Get category links based on category ID

It is simpler to get the category link based on the ID, directly using the Get_category_link () function.

Echo Get_category_link (23);

Get the category link based on the category alias

Getting the category link based on the category alias requires one more step, first using the Get_category_by_slug () function to get the taxonomy based on the alias, and then getting the category link.

Echo Get_category_link (Get_category_by_slug (' tips '));

Get category links by category name

According to the category name to get the category link and according to the category alias to get the principle of similar, are to get the category, and then get the link.

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

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.