Skip Navigation

[Closed] AJAX doesnt work with archives page with sliders instead of images

This support ticket is created 3 years, 11 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.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 5 replies, has 2 voices.

Last updated by Jamal 3 years, 11 months ago.

Assisted by: Jamal.

Author
Posts
#2238149
screenshot_archive.jpg

I am trying to: create an archives page for a toolset custom post type which has an image custom field. In the grid of wordpress loop I use a slider showing images of each post. When I use AJAX in custom search of the Archives Page the images on the sliders do not load. Instead, when I refresh the page or when I disable the AJAX, the images on each slider load properly.

Link to a page where the issue can be seen:

I expected to see: an archives page consisting of a grid of sliders with images from each post.

Instead, I got:an archives page consisting of a grid of sliders with blank. Images dont show although they appear to be loaded in the inspection.

#2238235

Hello and thank you for contacting the Toolset support.

I was able to reproduce this issue on a clean install hidden link
You can log in to it with the following URL hidden link

Unfortunately, this happens for views too. Otherwise, we could disable the archive for the post type, and use a view inside a page with the same slug as the archive URL.

I am escalating this to our 2nd Tier for further analysis and I'll get back to you as soon as we have something to share. In the meantime, I am afraid, you will have to disable AJAX on the archive.

#2239131

Our 2nd Tier team has worked on this and it wouldn't be easy to support the slider block on an archive template that has AJAX pagination.

I thought about a workaround, but it would not be easy to implement it for archives. Especially for taxonomy archives.

The workaround consists of using a legacy content template to generate an HTML markup that can support supports a Bootstrap carousel. hidden link

Check this content template and the custom Javascript code inside of it hidden link

<div id="carousel-[wpv-post-id]" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    [wpv-for-each field="wpcf-slider"]
      <div class="carousel-item">
        <!-- img class="d-block w-100" src="..." alt="First slide" --> 
        [types field="slider"][/types]
      </div>
    [/wpv-for-each]
  </div>
  <a class="carousel-control-prev" href="#carousel-[wpv-post-id]" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carousel-[wpv-post-id]" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

Javascript code:

jQuery('.carousel').each(function(){
    var carousel = jQuery(this);
    carousel.find('.carousel-item:first').addClass('active')
    carousel.carousel()
})

The custom Javascript code makes the first image active, then initialize the Bootstrap carousel.

This will work for the first page load. When the AJAX pagination completes, we'll need to run this code again to initialize the new page carousels.

Views do have a Javascript API that allows that. Read more about it here https://toolset.com/documentation/programmer-reference/adding-custom-javascript-code-to-views-that-use-ajax/
You can check an example here hidden link

jQuery( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
	/**
	* data.view_unique_id (string) The View unique ID hash
	* data.effect (string) The View AJAX pagination effect
	* data.speed (integer) The View AJAX pagination speed in miliseconds
	* data.layout (object) The jQuery object for the View layout wrapper
	*/
	jQuery('.carousel').each(function(){
            var carousel = jQuery(this);
            carousel.find('.carousel-item:first').addClass('active')
            carousel.carousel()
        })
});

However, for archive templates there is no similar API. To workaround it, we can hook into the AJAX request, wait for it until it completes and wait an additional time to let it update the results, then we can run the Javascript code. Something like:

jQuery('.carousel').each(function(){
    var carousel = jQuery(this);
    carousel.find('.carousel-item:first').addClass('active')
    carousel.carousel()
})

But, this will only work for pages when they are paged the first time. If they are paged again, Toolset won't perform the AJAX request, and will use its own cache. The code won't be run.

If the archive template is only for post type, and not for taxonomies, you can disable the archive for the custom post type, and use a page and a view for it.

I hope this makes sense. Let me know if you have any questions.

#2239135

Our 2nd Tier team asks if you are using captions for these images or no? There might be a workaround if captions are not used.

#2239163

Hello and thank you for your response!

No we don't use captions (although we would like to have the option in a future update). Just plain images organized in sliders; infact our custom post type (the one that we are trying to create an archive for) has only a slider and abutton for pdf downloads. The idea was to feed the archive page with the slider and the title of each of these posts.

#2239197

Disabling the captions for the slider will fix the issue for paginated pages. But, once you get back to a previous page, the issue reappears. I am letting the 2nd Tier team know this and I'll get back to you as soon as possible.

The topic ‘[Closed] AJAX doesnt work with archives page with sliders instead of images’ is closed to new replies.