我有以下代码(见下文)列出了一篇文章中的所有附加图像。我正试图修改这段代码,只列出前五幅图像,并从列表中排除特色图像。我们非常感谢您的帮助。提前谢谢。
<div class="entry-content">
<ul>
<?php
$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, \'thumbnail\' );
echo \'</li>\';
}
}
?>
</ul>
</div><!-- .entry-content -->
最合适的回答,由SO网友:birgire 整理而成
Did you try this:
$args = array(
\'post_type\' => \'attachment\',
\'posts_per_page\' => 5,
\'post_status\' => \'inherit\',
\'post_parent\' => $post->ID,
\'exclude\' => get_post_thumbnail_id( $post->ID )
);