2012-07-14 75 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>