Skip Navigation

[Resolved] adding anchor or scrolltop after manual pagnination and page reload

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 2 replies, has 2 voices.

Last updated by zachariahC 4 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1567327

Tell us what you are trying to do? After doing a manual pagination and full page reload I'm trying to scroll down to an anchor on the page. When initially coming to the site (the view is on the homepage) or when linking backing to the home page from another page I would want the page to load without the anchor being triggered. Only when moving between pages of the view would it scroll down to the anchor point on the page.

Is there any documentation that you are following? I've tried searching in multiple ways in the resolved support thread. Could only find solutions for ajax pagination.

Is there a similar example that we can see?

What is the link to your site?

#1567741

Hi,

Thank you for contacting us and I'd be happy to assist.

There is no direct method/feature available to include page's anchor in the view's pagination links, but you can use the following workaround to achieve the same:

1. You'll note that the URL attribute "wpv_view_count" is available in the URL, whenever the view's pagination link is used for navigation.

The value of that URL attribute can be acquired through the "wpv-search-term" shortcode:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-search-term

Example:


[wpv-search-term param="wpv_view_count"]

2. This shortcode can be used in conditional output block, to check whether the page was navigated through pagination link or not:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/

When the output of this shortcode will be empty, it would mean that the view's pagination is not used.

Example:


[wpv-conditional if="( '[wpv-search-term param="wpv_view_count"]' ne '' )"]

// show this content only when URL attribute 'wpv_view_count' has some value set

[/wpv-conditional]

3. Finally, you can include some custom script inside this conditional block, that scrolls to a specific ID or anchor on the page.
( ref: https://stackoverflow.com/a/18103556 )

Example:


[wpv-conditional if="( '[wpv-search-term param="wpv_view_count"]' ne '' )"]
<script>
jQuery(document).ready(function () {
    // Handler for .ready() called.
    jQuery('html, body').animate({
        scrollTop: jQuery('#what').offset().top
    }, 'slow');
});
</script>
[/wpv-conditional]

Note: You'll replace "what" with the actual target ID on your page and this block can be included anywhere in the view, other than the loop so that it doesn't repeat.
( screenshot: hidden link )

As a result, the script will only be included and thus execute, when the page is reloaded through the view's pagination link.

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

regards,
Waqar

#1568283

My issue is resolved now. Thank you!