get_media_items() - WordPress 函数参考中文文档

返回介绍

get_media_items()

发布于 2017-09-10 字数 2719 浏览 813 评论 0

get_media_items( int $post_id,  array $errors )

Retrieve HTML for media items of post gallery.


描述

The HTML markup retrieved will be created for the progress of SWF Upload component. Will also create link for showing and hiding the form to modify the image attachment.


参数

$post_id

(int)
(Optional)
Post ID.

$errors

(array)
(Optional)
Errors for attachment, if any.


返回值

(string)


源代码

File: wp-admin/includes/media.php

function get_media_items( $post_id, $errors ) {
	$attachments = array();
	if ( $post_id ) {
		$post = get_post($post_id);
		if ( $post && $post->post_type == 'attachment' )
			$attachments = array($post->ID => $post);
		else
			$attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
	} else {
		if ( is_array($GLOBALS['wp_the_query']->posts) )
			foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
				$attachments[$attachment->ID] = $attachment;
	}

	$output = '';
	foreach ( (array) $attachments as $id => $attachment ) {
		if ( $attachment->post_status == 'trash' )
			continue;
		if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
			$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-$id' class='hidden'></div><div class='filename hidden'></div>$item\n</div>";
	}

	return $output;
}

更新日志

Version 描述
2.5.0 Introduced.

相关函数

Uses

  • wp-includes/post.php:
    get_children()
  • wp-admin/includes/media.php:
    get_media_item()
  • wp-includes/post.php:
    get_post()

Used By

  • wp-admin/includes/media.php:
    media_upload_type_form()
  • wp-admin/includes/media.php:
    media_upload_gallery_form()
  • wp-admin/includes/media.php:
    media_upload_library_form()

User Contributed Notes

上一篇:get_media_item()

下一篇:get_metadata()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!