We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19554
    • 59 Posts
    Taking next and previous in the terms of Menu Index, how to fetch next and previous sibling of a document?
      • 10313
      • 375 Posts
      Have you found a solution for your task?

      I’m just in search of a way to achieve the document IDs of the "previous" and "next" siblings of a given document. I have found some solutions here that are overkill for me, but I think I will have a look into the "NavigateSiblings" code of Jason/Opengeek found here: http://modxcms.com/forums/index.php/topic,4847.0.html

      Martin
        • 3749
        • 24,544 Posts
        You could have two Template Variables called "previous" and "next" and just put the document ID of the previous and next docs in them. Then this code in your template would provide links to them:

        <a href = "[~[*previous*]~]">Previous</a>
        <a href = "[~[*next*]~]">Next</a>


        It’s not nearly as slick as what you have in mind, but would definitely work if you can’t find a better solution.  Later, you could adapt them by using @eval in those TVs with code to find the previous and next docs by menu index.

        [Update] After checking it out, OpenGeek’s snippet looks like a better solution. You could alter it to remove the "direct" and "template" modes since all you want is the URLs.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 10313
          • 375 Posts
          Thank you, this could be a way. But as you too already posted, I will indeed investigate Jasons code. My goal is to achieve a navigation bar like this:

          <prev 1 | 2 | 3 | 4 next>

          to browse the siblings of a given parent. The 1 through n was done very easyly with ditto, the rest comes now smiley
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I’ve used the PrevNextJump snippet modified to skip the Jump part. It seems to work just fine.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 10313
              • 375 Posts
              The thing is: Since I have tried to understand the code of NavigateSiblings, I finally understood what it actually does. Saving the prev and next links with templates in TV is exactly what I need. Thus, I’m using it now instead of coding my own.

              Martin