返回介绍

get_media_items()

发布于 2017-09-10 23:33:30 字数 2717 浏览 932 评论 0 收藏 0

get_media_items( int $post_id,  array $errors )

Retrieve HTML for media items of post gallery.


description

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;
}

更新日志

Versiondescription
2.5.0Introduced.

相关函数

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文