2013-07-31 41 views
1

我將此代碼包含到我的圖像附件模板(image.php)文件中以顯示當前帖子的縮略圖庫。wordpress禁用圖片在圖庫中查看

function show_all_gallery_thumbs() 
{ 
    global $post; 
    $post = get_post($post); 

    /* image code */ 
    $images =& get_children('post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->post_parent); 

    if($images) 
    { 
     $thumblist = '<ul class="thumbnails">'; 

     foreach($images as $imageID => $imagePost) 
     { 

      unset($the_b_img); 
      $the_b_img = wp_get_attachment_image($imageID, array(64,64)); 
      $thumblist .= '<li class="span1"><a href="'.get_attachment_link($imageID).'" class="thumbnail">'.$the_b_img.'</a></li>'; 

      } 

     $thumblist .= '</ul>'; 
    } 

    return $thumblist; 
} 

我該如何檢測正在查看哪個圖像並禁用/突出顯示圖庫中的圖像?

回答

0

你差不多去了。所有你需要做的是使用get_attachment_link()獲得當前的圖像,並將其與比較你get_attachment_link($imageID)

這裏是你的代碼

function show_all_gallery_thumbs() 
      { 
       global $post; 
       $post = get_post($post); 

       /* image code */ 
       $images =& get_children('post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->post_parent); 

       if($images) 
       { 
        $img_current = get_attachment_link(); //get current viewed img 

        $thumblist = '<ul class="thumbnails">'; 

        foreach($images as $imageID => $imagePost) 
        { 

         unset($the_b_img); 
         $the_b_img = wp_get_attachment_image($imageID, array(64,64)); 
         $img_list = get_attachment_link($imageID); 

         if ($img_current != $img_list) 
         { 
           $thumblist .= '<li class="span1"><a href="'.$img_list.'" class="thumbnail">'.$the_b_img.'</a></li>'; 
         } 
         else //If page img viewed is the same in list, remove href 
         { 
           $thumblist .= '<li class="span1">'.$the_b_img.'</li>'; 

         } 
         } 

        $thumblist .= '</ul>'; 
       } 

       return $thumblist; 
      } 
} 

documentation on get_attachment_link() is available here

+0

作品完美!謝謝您的幫助 :) – user2636556