您可以使用get_attached_media(), 作用我已将上述内容链接到抄本。
P、 这不是我自己的代码,直接来自WordPress Codex:
<ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => -1,
\'post_status\' => null,
\'post_parent\' => $post->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>\';
}
}
endwhile; endif; ?>
</ul>
EDIT
您可以尝试以下方式:
function get_attached_images() {
global $post;
$post_id = $post->ID;
$media = get_attached_media( \'image\', $post_id );
}