The application of Lightbox effect in WordPress photo _jquery

Source: Internet
Author: User
If you've already used Lightbox on your site, or some of the following experiences, you'll feel comfortable with it (provided you use jquery).
1. Specify which conditions apply the Lightbox effect
Add the following statement to the JS file in the Web site:
Copy Code code as follows:

$ (function () {
$ (' a[@rel *=lightbox] '). Lightbox ();
$ ('. Gallery a '). LightBox ();
});

This determines that only after adding "rel=lightbox" to the link, the link will appear lightbox effect, the second line of '. Gallery a ' is for WordPress original album, add this sentence, the photo album will also appear Lightbox effect.
2. Automatically add Rel=lightbox properties
Because in the above definition only with "Rel=lightbox" link will have effect, generally we need to each upload picture manually add "Rel=lightbox" this sentence. But this is a hassle, and we can make it automatically added to the picture with the link.
First automatically add a style for each p paragraph with a picture:
$ ("#content P:has (IMG)"). AddClass ("IMGBG");
For example, the above sentence is specified in the #content this area, as long as the paragraph with IMG, then add the style "IMGBG", so that its original no style of p paragraph into the <p class= "IMGBG" > Belt style;
Then automatically add the "Rel=lightbox" attribute to the link in the <p class= "IMGBG" > This section:
Copy Code code as follows:

$ (". IMGBG a"). attr ({
Rel: "Lightbox"
});

With the above two steps, all the pictures with links in the text will automatically perform the Lightbox effect.
3. Selectively load Lightbox
We do not need to load the whole station Lightbox effect. In general we use this effect in a separate article page. So we can put the Lightbox JS code out, and then in the WordPress header.php in this setting:
Copy Code code as follows:

<?php if (Is_single ()):?>
<script type= "Text/javascript" src= "<?php bloginfo (' Template_url ');? >/js/lightbox.js" ></script>
<?php endif?>

Further, if you want to perform the effect on only the article in the photo, you can accurately load the Lightbox only for the article labeled "Photo", set to read:
Copy Code code as follows:

<?php if (Is_single () && has_tag (' photo '):?>
<script type= "Text/javascript" src= "<?php bloginfo (' Template_url ');? >/js/lightbox.js.php" ></script >
<?php endif?>

The above points is my use of lightbox, I hope to help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.