如何将LIGHTBOX添加到附件?

时间:2012-02-27 10:25:20

标签: wordpress lightbox attachment

如何添加灯箱功能

  

的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>

1 个答案:

答案 0 :(得分:0)

你只需要将rel =“lightbox”添加到这样的href:

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

您可以参考文档以获取灯箱脚本的确切示例。