2012-07-14 136 views
0

我想顯示縮略圖旁邊我的文章在檔案頁面,但它只顯示縮略圖,如果帖子有一個特色的圖像。WordPress的:張貼縮略圖/張貼圖像附件

有沒有辦法將貼的圖像製作成縮略圖並將其顯示在存檔頁中?

目前我使用下面的代碼來顯示縮略圖,如果設置爲特色。

<?php if (has_post_thumbnail()) : ?> 
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > 
    <?php the_post_thumbnail(thumbnail, array('class' => 'alignleft')); ?> 
    </a> 
<?php endif; ?> 

這裏是網站http://n1bar.com/category/blog正如你所看到的第一篇文章有​​一個附加的圖像,但並未顯示在存檔頁面縮略圖。

任何幫助表示讚賞

回答

0

以下代碼可以給你一個帖子的所有圖像附件。 把它放在大的while循環中。 如果你只是想顯示1圖像,你可以修改下面的代碼,因爲我不確定你想顯示哪個圖像,如果有超過1個圖像附件。

<div class="allthumbs cf"> 
    <?php 

     $args = array(
      'post_type' => 'attachment', 
      'numberposts' => -1, 
      'post_status' => null, 
      'post_parent' => $post->ID, 
      'order' => 'ASC', 

     ); 

     $attachments = get_posts($args); 
     if ($attachments) { 
      foreach ($attachments as $attachment) { 
       $full_img_url = wp_get_attachment_image_src($attachment->ID, 'full'); 
       echo '<div class="imageWrapper zoom-able"><a href="' . $full_img_url[0] .'">' 
        .wp_get_attachment_image($attachment->ID, 'medium') . "</a></div>"; 
      } 
     }  
    ?> 
    </div>