get_children()获取子对象

目录

描述

get_children() retrieves attachments, revisions, or sub-pages, possibly by post parent. It works similar to get_posts().

get_children() 描述

用法

 <?php $children_array get_children$args$output ); ?> 

Default Usage

 

get_children() 用法

参数

As of Version 2.6, you must pass a non-empty post_type parameter (either attachment or page).

The following options are available in the $args array:

'numberposts'

(integer) (可选) Number of child posts to retrieve.

默认值: '-1'

'post_parent'

(integer) (可选) Pass the ID of a post or Page to get its children. Pass 0 to get attachments without parent. Pass null to get any child regardless of parent.

默认值: '0'

'post_type'

(string) (可选) Any value from post_type column of the posts table, such as attachment, page, or revision; or the keyword any.

默认值: '0'

'post_status'

(string) (可选) Any value from the post_status column of the wp_posts table, such as publish, draft, or inherit; or the keyword any.

默认值: 'any'

'post_mime_type'

(string) (可选) A full or partial mime-type, e.g. image, video, video/mp4, which is matched against a post's post_mime_type field.

默认值: None

Note: See get_posts() for a full list of $args parameters.

'output'

(constant) (可选) Variable type of the array items returned by the function: one of OBJECT, ARRAY_A, ARRAY_N.

默认值: OBJECT

get_children() 参数

返回值

(array) 

Associative array of posts (of variable type set by $output parameter) with post IDs as array keys, or an empty array if no posts are found.

Note: Prior to Version 2.9, the return value would be false when no children found.

get_children() 返回值

示例

If you just want to get or display attachments, it's probably a little easier to use get_posts() instead.

Show the first image associated with the post

This function retrieves the first image associated with a post

Show the first image associated with the post and re-key the array

In the example above, a primary array is keyed with the image ID (the exact thing which is being sought - since we don't know it how are we supposed to access it?). The code below provides an easier handle for the image information: the array $child_image. Should be used in the loop.

 

get_children() 示例

历史

添加于 版本: 2.0.0

get_children() 历史

源文件

get_children() 函数的代码位于 wp-includes/post.php.

get_children() 源文件

相关