您可以使用get_children
或get_posts
甚至WP_Query
获取当前帖子的附加图像ID
然后,您可以使用这些ID将附加的图像与wp_get_attachment_image()
下面是一个可以在小部件或边栏中使用的基本想法。(警告:未经测试)
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => -1,
\'post_status\' => null,
\'post_parent\' => get_queried_object_id()
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo \'<li>\';
echo wp_get_attachment_image( $attachment->ID, \'full\' );
echo \'<p>\'; echo apply_filters( \'the_title\', $attachment->post_title );
echo \'</p></li>\';
}
}