Skip Navigation

[Resolved] Trying to add a lightbox effect to a RFG view

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to add a lightbox effect to my View but it's not working as expected.

Solution: Enqueue the script file in your theme, then move the script that initializes the lightbox into the View's Loop Output JS editor.

Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 2.01 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by chrisC-25 5 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1273767

I am close to making this work, but it still is not loading the images correctly or allowing me to use the nav arrows to scroll.

If you click on the first image it shows nothing, if you click on the last it shows up then go back and click on first it shows, no scrolling.

See here:
hidden link

Images are below the video.

I followed the instructions here:
hidden link

What am I missing?
Here is the view:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
<div class="tz-gallery">
	<wpv-loop wrap="3" pad="true">
		[wpv-item index=1]
		<div class="row ">
			<div class="col-sm-6 col-md-4">[wpv-post-body view_template="loop-item-in-gallery-view"]</div>
		[wpv-item index=other]
			<div class="col-sm-6 col-md-4">[wpv-post-body view_template="loop-item-in-gallery-view"]</div>
		[wpv-item index=3]
			<div class="col-sm-6 col-md-4">[wpv-post-body view_template="loop-item-in-gallery-view"]</div>
		</div>
		[wpv-item index=pad]
			<div class="col-sm-6 col-md-4"></div>
		[wpv-item index=pad-last]
			<div class="col-sm-6 col-md-4"></div>
      </div>
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Here is the loop:

<div class="thumbnail"><a class="lightbox" href="[types field="gallery-image" output='raw'][/types]">
                        <img src="[types field="gallery-image" output='raw'][/types]" alt="[types field="image-name"][/types]">
                    </a></div>
<div class="caption">[types field="image-name"][/types]</div>
<div class="caption">[types field="image-description"][/types]</div>

<script src="<em><u>hidden link</u></em>"></script>
<script>
    baguetteBox.run('.tz-gallery');
</script>
#1273775

It's best to enqueue javascript in your theme if you're going to use it in your site. I would enqueue the baguettebox.js file in the theme using wp_enqueue_scripts instead of including it in the loop like this. https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts

Then move the baguetteBox.run command into the JavaScript editor below the Loop editor. That way it will run only once to initialize the system.

#1273845

Okay, I must have done something wrong, first time doing this.

I put the baguetteBox.js on the ftp in the child theme folder.

Following instructions related to my child theme I put this in functions.php:

function x_theme_name_scripts() {
    wp_enqueue_style( 'style-name', get_template_directory_uri() . '/css/example.css' );
    wp_enqueue_script( 'baguetteBox', get_template_directory_uri() . '/js/baguetteBox.js', array('jquery'), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'x_theme_name_scripts' );

Then moved

baguetteBox.run('.tz-gallery');

to js editor.

Now not working at all.

#1273849

Okay it looks like you enqueued the script correctly, I can see it show up now on your site. However, I'm still seeing the script tags in the loop like I saw before. May I log in and take a look?

#1273863

Okay I updated your functions.php file to enqueue the JavaScript file like this:

wp_enqueue_script( 'baguetteBox', get_stylesheet_directory_uri() . '/js/baguetteBox.js', array('jquery'), '1.0.0', true );

Now it looks like it's behaving more like expected. Can you confirm?

#1273867

Okay, so it was looking in the wrong place apparently. My issue is resolved now. Thank you!