2010-08-14 99 views

回答

2

您可以創建一個查詢,列出了所有帶有圖片的帖子,然後用wp_get_attachment_url, wp_get_attachment_image或wp_get_attachment_link。下面的代碼獲取所有帖子的所有圖像附件,然後將它們顯示在一個循環中(即用於圖像庫)。

<ul> 
     <?php 
     $wp_query = new WP_Query(array('post_type' => 'attachment','post_mime_type' =>'image','post_status' => 'inherit', 'posts_per_page' => '20', 'orderby' => 'date','order' => 'DESC')); 
     if($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();?> 
       <li> 
       <a href="<?php echo wp_get_attachment_url($post->ID); ?>" 
       class="post-images" 
       title="<?php the_title(); ?>" > 
       <img width="100" height="100" src="<?php echo wp_get_attachment_thumb_url($post->ID);?>" /></a> 
       </li> 
     <?php endwhile; ?> 
     </ul>