Detailed description of function usage for obtaining categories and subpages in WordPress development

Source: Internet
Author: User
This article describes how to use the get_category and get_children functions in WordPress development to obtain categories and subpages. For more information, see Get_category
Get_category may not be frequently used, but it is very useful. This function does not seem to introduce much on the Internet, so today we only translate the official WordPress English document.

Function description
Returns a specified category in the form of an array or object.

Function usage

 get_category( $cat, $out, $filter )

Parameter description
$ Cat: Category ID, or
$ Out Return value type [OBJECT, ARRAY_A, or ARRAY_N]
$ Filter
Function return value
Here we will mainly talk about the returned values of the object type,
All of them have annotations. For more information, see.

StdClass Object (// ID classification and tag mixing [term_id] => 5 // category name [Name] => Cat name // category alias [slug] => cat // N /A [term_group] => 0 // same as term_id [term_taxonomy_id] => 5 // classification, that is, the category or tag [taxonomy] => category // category description [description] => // parent ID [parent] => 70 // N/A [count] => 0 // Category ID [cat_ID] => 5 // N/A [category_count] => 0 // same description [category_description] => // same name [cat_name] => Category Name // same as slug [category_nicename] => category-name // same as parent [category_parent] => 70)

Get_children ()
Let's take a look at the use of this function. Get_children is somewhat similar to the get_posts function, but it is different. This function is mainly used to retrieve or return data. it is a function of the parent article, subarticle under the page, and attachment (important.

I hope some content in this article will be helpful to you.

Get_children function meaning
Get_children () this function is available since WordPress 2.0.0 and is mainly used to retrieve information such as attachments, versions, and subpages. The usage of get_children () and get_posts () is basically the same.

Function usage

$args = array( 'post_parent' => $postid, 'post_type' => 'attachment', 'numberposts' => 1, 'post_mime_type' => 'image', );if ($images = get_children($args))

Parameter description
$ Args ['numberposts']
(Integer) number of sub-articles to be retrieved. Optional; default value:-1 (unlimited)

$ Args ['post _ parent']
(Integer) pass the log or page number to obtain its sub-article. If a null value is passed, any sub-article can be obtained. Optional; default value: 0 (any parent article ?)

$ Args ['post _ type']
(Character) values in the post_type column in the document list, such as attachments, pages, or modifications; or keyword any. Default value: any

$ Args ['post _ status']
(Character) the value in the post_status column in the article list, such as published, draft, or inherited; or keyword any. Default value: any

$ Args ['post _ mime_type ']
The complete or incomplete mime type, slice, video, video/mp4, matches the post_mime_type field of the article.

$ Output
(Constant) the variable type of the array items returned by any function in OBJECT, ARRAY_A, and ARRAY_N. Optional; default value: OBJECT
Summary
Get_children () is generally used in the topic to call the image attachments in the article. that is to say, as long as you upload the image, even if your topic does not support special images or you have not set special images, we can use this function to retrieve the images you have uploaded in this article. Although this has some limitations, however, it is enough to supplement the special image. As for the use of other sub-item content, I personally feel that it is not very useful. In addition, because the paging of the article is generally not used, no demo is used to test the paging. If you are studying the get_children () function, I hope this article will bring you good luck.

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.