使用switch_to_blog
将博客上下文切换到特定的博客ID。从那里开始get_posts
的attachment
类型并切换回当前上下文restore_current_blog
.
类似这样:
switch_to_blog( $blog_id );
$args = array( \'post_type\' => \'attachment\', \'numberposts\' => 5, \'orderby\' => \'post_date\', \'order\'=> \'ASC\' );
foreach ( get_posts( $args ) as $attachment ) {
echo wp_get_attachment_image( $attachment->ID );
}
restore_current_blog();