我必须承认,我没有时间玩3.5的新媒体库之类的东西,但我只使用代码,而不考虑WP的库功能。。。
您提供的代码使用get_children() 使用查询变量post_parent 设置为get_the_ID() (内容循环中当前正在处理的post对象的ID)。因此get_children() 只能查询当前帖子的附件,and no others.
在示例的术语中,当在循环上下文中执行代码时,处理Post 3,无法检索附加到Post 1和Post 2的附件,因为它专门要求附加到Post 3的附件。
不幸的是,Wordpressnot 支持将多个值传递到post_parent 查询var,以便以所需的方式从其他帖子中检索附件,您必须获取包含帖子的附件的帖子id(帖子1和帖子2),并执行调用get_children() 对于每个,替换post_parent “的值”get_the_ID()“具有相应的ID。
通过巧妙地利用WP_Query 然而,我相信你正在寻求的解决方案(或者我假设你正在寻求——你实际上从未问过问题;)看起来像是
$attachmentParentIds = getAttachmentParentIds( get_the_ID() );
foreach( $attachmentParentIds as $attParentId ) {
    $attachments = get_children( array(\'post_parent\' => $attParentId, \'post_type\' => \'attachment\', \'post_mime_type\' =>\'image\') );
    foreach ( $attachments as $attachment_id => $attachment ) {
        echo wp_get_attachment_image( $attachment_id, \'medium\' );
    }
}
 它使用如下函数
//Returns an array of post IDs containing attachments that should be displayed
//on the post indicated by the passed post ID.
function getAttachmentParentIds( $intPostId ) {
    $ids = array();
    //Figure out which posts contain attachments that need to be displayed for $intPostID
    //...
    return $ids; //return an array of IDs
}
 作为逻辑的占位符,用于确定哪些帖子包含需要为传递的帖子ID显示的附件。我对您的实现或应用程序的程度不确定,因此我不知道该逻辑的细节可能涉及您的项目。