如何从帖子中只获得一定数量的图片(减去特色图片)?

时间:2013-11-22 作者:bprocell

我有以下代码(见下文)列出了一篇文章中的所有附加图像。我正试图修改这段代码,只列出前五幅图像,并从列表中排除特色图像。我们非常感谢您的帮助。提前谢谢。

<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 -->

1 个回复
最合适的回答,由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 )
  );
结束

相关推荐

Define Folder to save Images

插件将图像保存到/PLUGINNAME/Images,但我希望它移动到/uploads插件中的代码如下define(\'WPR_URLPATH\', WP_PLUGIN_URL.\'/\'.plugin_basename( dirname(__FILE__) ).\'/\' ); $wpr_saveurl = WPR_URLPATH . \"images\"; $wpr_cache = ABSPATH . \"wp-content/plugins/\". plugin_basename(