我正在寻找一种解决方案,以排除每篇文章中的特色图像/缩略图,因此我发现this great piece of code 并将其添加到函数中。php。它工作得很好,除了一件事:它使Lightbox jquery插件变得无用。
我在代码中看到的区别是这样的。使用代码:
<a href=\'http://site.com/wp-content/uploads/2012/01/main-image-2.jpg\' title=\'main-image-2\'><img width="150" height="150" src="http://gamebox.la/wp-content/uploads/2012/01/main-image-2-150x150.jpg" class="attachment-thumbnail" alt="main-image-2" title="main-image-2" /></a>
无:
<a href=\'http://site.com/wp-content/uploads/2012/01/main-image-2.jpg\' title=\'main-image-2\' rel="lightbox[170]"><img width="150" height="150" src="http://gamebox.la/wp-content/uploads/2012/01/main-image-2-150x150.jpg" class="attachment-thumbnail" alt="main-image-2" title="main-image-2" /></a>
过滤器似乎对post\\u gallery做了一些事情,使WP不显示Lightbox部分(missing rel=“Lightbox[]”),但我不明白为什么它会这样做。
函数中的参考代码。php发件人here:
function exclude_thumbnail_from_gallery($null, $attr)
{
if (!$thumbnail_ID = get_post_thumbnail_id())
return $null; // no point carrying on if no thumbnail ID
// temporarily remove the filter, otherwise endless loop!
remove_filter(\'post_gallery\', \'exclude_thumbnail_from_gallery\');
// pop in our excluded thumbnail
if (!isset($attr[\'exclude\']) || empty($attr[\'exclude\']))
$attr[\'exclude\'] = array($thumbnail_ID);
elseif (is_array($attr[\'exclude\']))
$attr[\'exclude\'][] = $thumbnail_ID;
// now manually invoke the shortcode handler
$gallery = gallery_shortcode($attr);
// add the filter back
add_filter(\'post_gallery\', \'exclude_thumbnail_from_gallery\', 10, 2);
// return output to the calling instance of gallery_shortcode()
return $gallery;
}
add_filter(\'post_gallery\', \'exclude_thumbnail_from_gallery\', 10, 2);
提前多谢!
UPDATE: 我找到了这个http://core.trac.wordpress.org/ticket/14130 它说它添加了filter post\\u gallery\\u输出,但我不知道为了尝试其他解决方案,我必须在当前代码中修改哪些内容。