Skip Navigation

[Resolved] Display [wpv-post-next-link] and [wpv-post-previous-link] as raw html link

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

Problem: I would like to design custom next and previous links, but the wpv-post-next-link and wpv-post-previous-link shortcodes produce full link tags. I need to access only the URLs.

Solution: Please add this code to your theme's functions.php file:

function ts_get_adjacent_post_url_func($atts) {
  global $post;
  $previous = ($atts['previous'] == "1");
  $adjacent = get_adjacent_post( false, '', $previous);
  return get_the_permalink($adjacent);
}
add_shortcode("ts_get_adjacent_post_url", "ts_get_adjacent_post_url_func");

Then you can access the next and previous post URLs in a Content Template like this:

Next URL: [ts_get_adjacent_post_url previous="0"]<br />
Previous URL: [ts_get_adjacent_post_url previous="1"]<br />
This support ticket is created 6 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
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 6 replies, has 2 voices.

Last updated by Christian Cox 6 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#619453

I'm trying to wrap an icon/image with a navigation link so users can navigate back and forth through posts types when they click on a button.
Here is a link to a page where I'm trying to achieve this: hidden link
See the arrows on the right - I'd like these to be use to move forward/back through posts.
Thanks!

#619545

Hi, the wpv-post-next-link and wpv-post-previous-link shortcodes are designed to output an entire link tag, not just a link URL. I think that a custom shortcode would be required to output just a link URL. What determines the order of these posts?

#619651

Thanks Christian! The posts will be ordered by Menu Order.

#619757

Please add this code to your theme's functions.php file:

function ts_get_adjacent_post_url_func($atts) {
  global $post;
  $previous = ($atts['previous'] == "1");
  $adjacent = get_adjacent_post( false, '', $previous);
  return get_the_permalink($adjacent);
}
add_shortcode("ts_get_adjacent_post_url", "ts_get_adjacent_post_url_func");

Then you can access the next and previous post URLs in a Content Template like this:

Next URL: [ts_get_adjacent_post_url previous="0"]<br />
Previous URL: [ts_get_adjacent_post_url previous="1"]<br />
#621901

Brilliant, thank you Christian - that works perfectly!

#626915

Hi Christian,

Thanks again for your help with this - I might be asking too much - but is it possible to hide the 'Next' link, when there is no 'next' item? Same with 'Previous'.

See here: hidden link (pressing 'Next' simply reloads the page as this is the final item in the archive).

and here: hidden link (pressing 'Previous" simply reloads the page as this is the first item in the archive).

Thanks!
Kate

#626967

Hi, you could probably use conditional HTML to do that. If the URL of the next or previous link is identical to the URL of the current post, then do not display the link. If the URLs are different, then display the link. You may need to add "ts_get_adjacent_post_url" to Toolset > Settings > Frontend Content > Third party shortcode arguments, so you can use it in a conditional. You can access the current page's URL like this:

[wpv-post-url id='$current_page']

More info about using conditional HTML here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

If you need more detailed assistance, please open a new ticket where we can discuss the code.