wordpress禁用图像在图库中查看

时间:2013-07-31 05:04:44

标签: wordpress

我将此代码包含在我的图像附件模板(image.php)文件中,以显示当前帖子的缩略图库。

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;
}

如何检测正在查看的图像并禁用/突出显示我的图库缩略图中的图像?

1 个答案:

答案 0 :(得分: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