Use of WordPress photo lightbox Effects

Source: Internet
Author: User

If lightbox is already used on your website, or the following experiences are also appropriate (provided that JQuery is used ).
1. specify the conditions under which Lightbox effects are used
Add the following statement to the website's js file:
Copy codeThe Code is as follows:
$ (Function (){
$ ('A [@ rel * = lightbox] '). lightBox ();
$ ('. Gallery A'). lightBox ();
});

In this way, it is determined that only after "rel = lightbox" is added to the link will the lightbox effect be displayed for the link '. gallery a' is for the original album generated in WordPress. After this sentence is added, the lightbox effect will also appear in the photo album.
2. automatically add the rel = lightbox attribute
In the preceding definition, only links with "rel = lightbox" have an effect. Generally, we need to manually add "rel = lightbox" to each uploaded image. However, this is troublesome. We can make it automatically add images with links.
First, automatically add a style for each p Section with an image:
$ ("# Content p: has (img)"). addClass ("imgbg ");
For example, the above sentence is specified in the # content area. If the section contains img, the style "imgbg" is added ", change the original p Paragraph without a style to a style with <p class = "imgbg">;
Then, the link in the <p class = "imgbg"> section is automatically added with the "rel = lightbox" attribute:
Copy codeThe Code is as follows:
$ (". Imgbg a"). attr ({
Rel: "lightbox"
});

After the above two steps, all the images with links in the text will automatically execute the lightbox effect.
3. selectively load lightbox
We do not need to load lightbox across the site. In general, this effect is used only on individual article pages. Therefore, we can separate the js Code of lightbox and set it in header. php In WordPress as follows:
Copy codeThe Code is as follows:
<? Php if (is_single ():?>
<Script type = "text/javascript" src = "<? Php bloginfo ('template _ url');?> /Js/lightbox. js "> </script>
<? Php endif?>

Furthermore, if you want to perform this effect only for the photos, you can accurately load lightbox only for the articles marked with "Photos". The setting is changed:
Copy codeThe Code is as follows:
<? Php if (is_single () & has_tag ('photos '):?>
<Script type = "text/javascript" src = "<? Php bloginfo ('template _ url');?> /Js/lightbox. js. php "> </script>
<? Php endif?>

The above points are my use of lightbox. I hope it will help you.

Related Article

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.