如何添加灯箱功能
rel="灯箱"
到下面的代码
<a href="<?php echo wp_get_attachment_url($post->ID); ?>" title="<?php echo wp_specialchars( get_the_title($post->ID), 1 ) ?>"><?php echo wp_get_attachment_image($post->ID, 'large' ); ?></a>
您只需要在a href中添加rel="lightbox",如下所示:
<a rel="lightbox" href="<?php echo wp_get_attachment_url($post->ID); ?>" title="<?php echo wp_specialchars( get_the_title($post->ID), 1 ) ?>"><?php echo wp_get_attachment_image($post->ID, 'large' ); ?></a>
除此之外,我建议您浏览您正在使用的灯箱的演示/教程/文档。它还需要包含适当的js和文件。您还需要使用它的简单jquery代码对其进行初始化。像这样:
<script type="text/javascript">
$(function() {
// Use this example, or...
$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
// This, or...
$('#gallery a').lightBox(); // Select all links in object with gallery ID
// This, or...
$('a.lightbox').lightBox(); // Select all links with lightbox class
// This, or...
$('a').lightBox(); // Select all links in the page
// ... The possibility are many. Use your creative or choose one in the examples above
});
</script>
关于lightbox脚本的确切示例,您可以参考文档。