检索帖子库的媒体项目的HTML。

原型

get_media_items( int $post_id, array $errors )

描述

将为SWF上载组件的进度创建检索到的HTML标记。还将创建用于显示和隐藏表单的链接以修改图像附件。

参数

$post_id (int) (Optional)  帖子ID。

$errors (array) (Optional) 附件错误,如果有的话。

返回值

(string)  

源文件

路径:wp-admin/includes/media.php

<?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>$itemn</div>";
	}
	return $output;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_media_items/