从帖子附件排除多个帖子缩略图

时间:2011-09-08 作者:Danyo

我正在尝试从附件中排除多个帖子缩略图。

我的函数中设置了以下缩略图。php:

$thumb = new MultiPostThumbnails(array(
    \'label\' => \'Client Logo\',
    \'id\' => \'client-logo\',
    \'post_type\' => \'clients\'
    )
);

$thumb = new MultiPostThumbnails(array(
    \'label\' => \'Portfolio Home Image\',
    \'id\' => \'port-home-image\',
    \'post_type\' => \'clients\'
    )
);

$thumb = new MultiPostThumbnails(array(
    \'label\' => \'Home Slide Image\',
    \'id\' => \'home-slide-image\',
    \'post_type\' => \'clients\'
    )
);
然后,我在循环中得到了以下代码,以引入所有图像附件并对其进行分解

<?php
      $thumb_id = get_post_thumbnail_id( $post_id );
      $args = array(
      \'post_type\' => \'attachment\',
      \'numberposts\' => $nimg,
      \'post_mime_type\' => \'image\',
      \'post_status\' => null,
      \'post_parent\' => $post->ID,
      \'exclude\' => $thumb_id
      );
      $attachments = get_posts($args);
      if ($attachments) {
      foreach ($attachments as $attachment) {
      //echo apply_filters(\'the_title\', $attachment->post_title);
      echo wp_get_attachment_image( $attachment->ID, array (650,650));

     }
      }

?>
该行:$thumb_id = get_post_thumbnail_id( $post_id ); 排除特色帖子缩略图。

关于如何排除其他3个缩略图,有什么想法吗?

任何帮助都将不胜感激。

谢谢Danyo

http://wordpress.org/extend/plugins/multiple-post-thumbnails

2 个回复
SO网友:Doug
     $thumb_id = get_post_thumbnail_id(get_the_ID());
     $bg_id = MultiPostThumbnails::get_post_thumbnail_id(\'work\', \'background-image\', $post->ID);
     $args = array(
       \'post_type\' => \'attachment\',
       \'numberposts\' => -1,
       \'post_status\' => null,
       \'post_parent\' => $post->ID,
       \'exclude\' => array($thumb_id, $bg_id)

      );
SO网友:koskoz

我只修改了“排除”行。它没有经过测试,但应该可以工作。

<?php
      $thumb_id = get_post_thumbnail_id( $post_id );
      $args = array(
      \'post_type\' => \'attachment\',
      \'numberposts\' => $nimg,
      \'post_mime_type\' => \'image\',
      \'post_status\' => null,
      \'post_parent\' => $post->ID,
      \'exclude\' => $thumb_id, MultiPostThumbnails::get_post_thumbnail_id(\'clients\', \'client-logo\', $post_id), MultiPostThumbnails::get_post_thumbnail_id(\'clients\', \'port-home-image\', $post_id), MultiPostThumbnails::get_post_thumbnail_id(\'clients\', \'home-slide-image\', $post_id)
      );
      $attachments = get_posts($args);
      if ($attachments) {
      foreach ($attachments as $attachment) {
      //echo apply_filters(\'the_title\', $attachment->post_title);
      echo wp_get_attachment_image( $attachment->ID, array (650,650));

     }
      }

?>

结束

相关推荐

Double thumbnails?

是否可以使用缩略图机制两次?我发现缩略图API非常有用,它允许用户在其中放置自己的图形,以便我可以轻松控制大小和位置。他们所要做的就是记住点击特色图片。我想在我的页面上有两个这样的机制,你知道我该怎么做吗?最好是手工编码。