Can we create a Prev-Slug?

Continuing the discussion from Next parent slug:

I want to provide back links. They are complementary to next-slugs but work in the opposite direction, they would generate a link to the previous document.

Am I able to do this in a template? What would the code look like?

It’s not too hard to do in a template, just a little tricky.

Start by setting a global variable to hold the title of the previous page.

<?set prior-page = "" ?>

Follow this with your nextrec command.


Then, wherever you want the prior-page link to appear, you would want something like the following.

<?if "=$prior-page$=" ?>
Prior Page: 
<a href="=$prior-page&f$=">

And then at some point before the loop command:

<?set prior-page = "=$title$=" ?>

This assumes you’ve sorted the input into the desired sort sequence.

Hope this helps!

Let me know if questions or problems!

1 Like

Nice. That worked once I added the “.html” extension to the template code for the link.

<a href="=$prior-page&f$=.html">
1 Like