Skip Navigation

[Resolved] Reloading the page after last pagination item

This support ticket is created 4 years, 8 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: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 4 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1570659

Hi there, I wanted to know how I could reload the page at the end of a slider pagination to pull in the new post content.

#1573157

Hi Rohan,

Thank you for waiting, while I performed some tests.

I was able to find a way to execute a script only after the last page item has been loaded, using the "wpv-pager-next-page" shortcode.
( ref: https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-pager-next-page )

This shortcode shows the next pages link in the view and in that link, the next page number is in the "wpv_paged" URL parameter.

But when the last page in the view is loaded, this "wpv_paged" URL parameter is not set.

You can first add this shortcode in your view's loop, with a special class "hidden-next-page-link":


[wpv-pager-next-page class="hidden-next-page-link"]Next[/wpv-pager-next-page]

Note: Since we don't actually need this link for navigation through pages, you can use custom CSS code to hide it.

Next, in the view's "JS editor" tab, you can include the updated script, which only refreshes the page, once the last pagination item has been loaded:
( by looking for the "wpv_paged" URL parameter value in the generated next page link )


( function( $ ) {
	$( document ).ready( function(){
		// execute when pagination completes
		$( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
			// get the href value from the hidden next page link
			var pageURL = $("a.hidden-next-page-link").attr("href");
			// if that href value doesn't include wpv_paged attribute, it means that this is the last page
			if (pageURL.indexOf("wpv_paged=") < 1) {
				// reload the page
				setTimeout(function () { location.reload(true); }, 5000);
			}
		});
	});
})( jQuery );

I hope this helps and for more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar