Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best use practice with WordPress? #269

Closed
paaljoachim opened this issue Dec 23, 2015 · 8 comments
Closed

Best use practice with WordPress? #269

paaljoachim opened this issue Dec 23, 2015 · 8 comments

Comments

@paaljoachim
Copy link

Hey

I am just wondering about best use with WordPress.

  1. Selecting specific images to use it with
  2. Using it for all images.

Thanks.

@paaljoachim
Copy link
Author

paaljoachim commented Dec 27, 2015

I made a new lightgallery folder and added: lightgallery.css, lightgallery.min.js and a new file lightgallery-init.js.

The init.js file contains:
jQuery(document).ready(function($) {
$('a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"], a[href$=".gif"]').lightGallery();
});
});

The functions.php file (in the root of the child theme) contains:

* Light Gallery - http://sachinchoolur.github.io/lightGallery/ */
add_action('wp_enqueue_scripts', 'enqueue_lightgallery');
function enqueue_lightgallery() {
    wp_enqueue_style('lightgallery_style', get_stylesheet_directory_uri(). '/lightgallery/lightgallery.css' );

wp_enqueue_script('lightgallery_min_script',  get_stylesheet_directory_uri(). '/lightgallery/lightgallery.min.js', array('jquery'));
   wp_enqueue_script('lightgallery_init_script',  get_stylesheet_directory_uri(). '/lightgallery/lightgallery-init.js', array('jquery'));

/*--- Lightgallery plugins---*/

}

When I get it to work I will add on to this article:
http://easywebdesigntutorials.com/adding-a-lightbox-to-wordpress-without-using-a-plugin/

@Flyingsirkus
Copy link

Hi
Tried this, it worked for me.

jQuery(document).ready(function($) {
$('#some_id').lightGallery({
selector: 'a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"], a[href$=".gif"]'
});
});

@abnersajr
Copy link
Collaborator

@paaljoachim for all images the @Flyingsirkus solution works like charm.
Thanks for the reference 👍

@paaljoachim
Copy link
Author

Hmm could one of you guys post the solution that works. I am just not seeing it - as in not getting it to work correctly yet. Thanks!

I am working on Light Gallery working for all images without having to go into each html and add lightgallery inside the div tag.

@Codevz
Copy link

Codevz commented Mar 29, 2016

@paaljoachim try it like this:

    $('body').lightGallery({
        selector: 'a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"], a[href$=".gif"]'
    });

@paaljoachim
Copy link
Author

Hi Codevz. Thank you.

I adjusted the code I am using inside the lightgallery-init.js file, but still no go.

If someone could send me the files or paste the procedure they are getting to work here in the thread that would be helpful. As mentioned when I get it to work on my end I will write a tutorial for it.
It would be great to get images and at the same time images in a gallery to work.
Thanks guys!

@Codevz
Copy link

Codevz commented Jun 28, 2016

@paaljoachim I'm using this and works fine for me:

function codevzGallery() {
    'use strict';

    var a = '.lightbox,a[href$=".jpg"],a[href$=".jpeg"],a[href$=".png"],a[href$=".gif"]',
        b = $( 'body' ),
        d = b.data( 'lightGallery' );
    if ( d ) {
        d.destroy( true );
    }
    if ( $.fn.lightGallery ) {
        b.attr( 'data-lightGallery', 1 ).lightGallery( { selector: a } );
    }
}

and then

codevzGallery();

@hokutonanto
Copy link

Hi there,

I'm trying to do the same thing, but couldn't figure this out yet.
I was following paaljoachim's method, but then I get an error when I open the page:

/* Light Gallery - http://sachinchoolur.github.io/lightGallery/ */ add_action('wp_enqueue_scripts', 'enqueue_lightgallery'); function enqueue_lightgallery() { wp_enqueue_style('lightgallery_style', get_stylesheet_directory_uri(). '/lightgallery/lightgallery.css' ); wp_enqueue_script('lightgallery_min_script', get_stylesheet_directory_uri(). '/lightgallery/lightgallery.min.js', array('jquery')); wp_enqueue_script('lightgallery_init_script', get_stylesheet_directory_uri(). '/lightgallery/lightgallery-init.js', array('jquery')); /*--- Lightgallery plugins---*/

I must admit I'm quite confused about the steps to follow.
I thought that, in order to add a jquery plugin to WP, I would need to copy it in the plugins folder and not in the theme folder as paaljoachim suggested.
I would greatly appreciate if anyone who managed to install lightGallery correctly in WP, would post the exact steps to follow (I can get easily lost at tweaking PHP files).

Thanks in advance!
Piero

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants