2011-03-09 40 views

回答

1

想通了。

只需要添加这个添加到functions.php

<?php 
function postimage($size=medium,$num=1,$lighbox=1) { 
    if ($images = get_children(array(
     'post_parent' => get_the_ID(), 
     'post_type' => 'attachment', 
     'numberposts' => $num, 
     'order' => 'ASC', 
     'orderby' => 'ID', 
     'post_mime_type' => 'image',))) 
    { 
     foreach($images as $image) { 
      $attachmenturl=wp_get_attachment_url($image->ID); 
      $attachmentimage=wp_get_attachment_image($image->ID, $size); 
      $img_title = $image->post_title; 
      $img_desc = $image->post_excerpt; 
      if ($size != "full"){ 
       echo '<a href="'.$attachmenturl.'" rel="lightbox" title="'.$img_desc.'">'.$attachmentimage.'</a>'.$img_title.''; 
      } else { 
       echo '<img src="'.$attachmenturl.'">'; 
      } 
     } 
    } else { 
     echo "No Image"; 
    } 
} 
?> 

然后将其添加到页面后(在我的情况的single.php)

<?php postimage('thumbnail'); ?> 

现在在某个帖子上传任何图片会自动添加。