So, after searching around for a solution to the Prev/Next buttons in articles to link to nearby articles/posts, I decided to use someone’s solution and I hope this positively continues the discussion from Native linking to previous and next post or page using CMS:
I’ve modified @hammerhouse’ original prohack to include article/post titles. You can see the additional
vars from his code.
Granted, if this were native feature of @webflow then we wouldn’t be doing this, but I figured I’d add on to an already wonderful solution.
Add an Heading (H2, H3, etc.) element inside the anchor, to be used as an element to be targeted by the script.
Add in these two new
vars inside the script:
var next_title = $('#post_list .w--current').parent().next().find('a').text();
var previous_title = $('#post_list .w--current').parent().prev().find('a').text();
Then, near the end of the code add in two bits to set the text of the links using our new
Make sure you add those IDs to Webflow elements that you are using for the text, something like this:
<a href="#" id="previous_button"><h4 id="previous_title">Loading</h4></a>
<a href="#" id="next_button"><h4 id="next_title">Loading</h4></a>
Then you should be all set. Here’s hoping the wishlist makes this easier in the future.
Also, I have more than 2000 CMS articles on my site, so this works despite that.