1

我将此代码包含在我的图像附件模板 (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;
}

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

4

1 回答 1

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

有关 get_attachment_link() 的文档可在此处获得

于 2013-08-12T16:47:14.283 回答