How to implement next and previous post links #24
Replies: 2 comments 1 reply
-
That makes perfect sense. There might already be some support here to help you... The challenge with next/previous traversal is that the documents can be cloned along the way (and often are). So at whatever stage you "lock in" the next/previous metadata, if the set of documents are cloned after that, the To address this, I created extensions on
Wanting that to change based on archive is tricky though since the archives are all about showing lists and link to the same document regardless of where the link originated. One approach might be to calculate next/previous from each archive page and pass that in as a query string. Another would be to pass an archive name or some other identifier as a query string and then calculate all possible next/previous links during generation and toggle in JS from that identifier. Let me noodle on this one a bit and see if I come up with anything better. |
Beta Was this translation helpful? Give feedback.
-
I'm waiting to see how badly it seems to be needed before doing anything else. |
Beta Was this translation helpful? Give feedback.
-
I'd like to modify
_posts.cshtml
so that each post (IsPost: true) displays links for the next and previous post.Existing
Next
andPrevious
properties of the document relate to pagination, so they are no help and are null anyway. Further, the ideal solution would give a different value for next and previous according to the particular archive from which we arrived at the post. So, if we came from the main Index page, we'd get the next pst on that list, if we came from a tag we'd get the next item from that archive.Thinking about this, I've come to the conclusion that I need to have some sort of properties set on the originating list itself. But before digging into it I'd like to make sure there isn't something existing I can hook into.
If I need to solve it myself, it seems to me that I need to deal with two distinct problems:
The post must "know" what archive it was linked from. If not from an archive, I can default to the main Index or not display any links at all.
The archive document has to provide some property that will give the next and previous docs.
All said, my preference is to use what's there already.
Beta Was this translation helpful? Give feedback.
All reactions