Funny. I just wrote a snippet to manage next/previous links in a folder (as well as creating a page numbers thing.. 1 2 3 4 etc.). It doesn’t have the issue you talk about because it is based on menuindex and is quite indifferent to id.
I haven’t "released" it yet because I figured someone out there had already made such a thing (though I couldn’t find it). And I still don’t know where you got your "NextJumpPrev" snippet. But I guess someone has written something similar. Anyway, if you’re interested, I’ll slap the code here (I call it "FolderPagesNav"):
<?php
/*
* Snippet: FolderPagesNav
*
* Creates sequential navigation links in the form of previous, next, and list
* of page numbers.
*/
/* -----------------------------------------------------------------------------
* CONFIG
* -----------------------------------------------------------------------------
* All config parameters may be set in snippet call, or default values can be
* changed here.
*/
/* $parentFolder
* The ID number of the folder, whose children we want to consider pages in our
* navigation.
*/
$parentFolder = (isset($parentFolder)) ? $parentFolder : 0;
/* $prevPh [ string ]
* Previous link placeholder name.
*/
$prevPh = (isset($prevPh)) ? $prevPh : 'prevPh';
/* $prevLinkOn [ string ]
* What the previous page hyperlink will surround if there is a previous page.
* Could be a text string (e. g. "Prev"), an image, etc. If using an image
* (which should include the whole tag), replace = (equal sign) with || (double
* pipe) to avoid the snippet parameters being processed incorrectly.
*/
$prevLinkOn = (isset($prevLinkOn)) ? $prevLinkOn : 'Previous';
/* $prevLinkOff [ string ]
* A string to fill the previous link placeholder with if no previous page
* exists (i.e. on the first page). If using an image (which should include the
* whole tag), replace = (equal sign) with || (double pipe) to avoid the snippet
* parameters being processed incorrectly.
*/
$prevLinkOff = (isset($prevLinkOff)) ? $prevLinkOff : 'Previous';
/* $nextPh [ string ]
* Placeholder name for the "next page" link.
*/
$nextPh = (isset($nextPh)) ? $nextPh: 'nextPh';
/* $nextLinkOn [ string ]
* What the previous page hyperlink will surround if there is a previous page.
* Could be a text string (e. g. "Prev"), an image, etc. If using an image
* (which should include the whole tag), replace = (equal sign) with || (double
* pipe) to avoid the snippet parameters being processed incorrectly.
*/
$nextLinkOn = (isset($nextLinkOn)) ? $nextLinkOn: 'Next';
/* $nextLinkOff [ string ]
* A string to fill the next link placeholder with if no next page exists (i. e.
* on the last page). If using an image (which should include the whole tag),
* replace = (equal sign) with || (double pipe) to avoid the snippet parameters
* being processed incorrectly.
*/
$nextLinkOff = (isset($nextLinkOff)) ? $nextLinkOff : 'Next';
/* $numberLinePh
* The placeholder name for the number line - which is just a set of page
* numbers dumped out.
*/
$numberLinePh = (isset($numberLinePh)) ? $numberLinePh : 'numberLinePh';
/* $currentPageLinked [ 1 | 0 ]
* Boolean toggle to determine if the current page in the number line is linked.
*/
$currentPageLinked = (isset($currentPageLinked)) ? $currentPageLinked : 0;
/* $numberLineMax
* Maximum number of page numbers to show in the line. The default 0 is ALL page
* numbers. Odd numbers work best - even may have unpredictable results.
*/
$numberLineMax = (isset($numberLineMax)) ? $numberLineMax : 0;
/* $numberLineSeparator [ string ]
* What to put inbetween slide numbers.
*/
$numberLineSeparator = (isset($numberLineSeparator)) ? $numberLineSeparator : '';
/* $classPrefix
* FolderPagesNav will generate classes of its own, but is happy to put insert a
* prefix to avoid style name clashes.
*/
$classPrefix = (isset($classPrefix)) ? $classPrefix : 'fpn_';
/* -----------------------------------------------------------------------------
* End config
* -------------------------------------------------------------------------- */
// Get available pages from folder in order
if ( !$slides =$modx->getActiveChildren($parentFolder,'menuindex','ASC','id, pagetitle, menutitle') )
{
return FALSE;
}
// Initialize
$seenCurrent = FALSE;
$nextReset = FALSE;
$numberLine = '';
$currentSlideArray = array();
$afterSlideArray = array();
$beforeSlideArray = array();
$prevLinkOn = str_replace('||','=',$prevLinkOn);
$prevLinkOff = str_replace('||','=',$prevLinkOff);
$nextLinkOn = str_replace('||','=',$nextLinkOn);
$nextLinkOff = str_replace('||','=',$nextLinkOff);
$prevLink = '<span class="'.$classPrefix.'noPrevSlide">'.$prevLinkOff.'</span>';
$nextLink = '<span class="'.$classPrefix.'noNextSlide">'.$nextLinkOff.'</span>';
// Cycle through each document
for ( $s = 0; $s < count($slides); $s++ )
{
// If this is current page, trigger seenCurrent and continue
if ( $slides[$s]['id'] == $modx->documentObject['id'] )
{
$seenCurrent = TRUE;
}
// If we haven't seen the current page yet, reset previous link
if ( !$seenCurrent )
{
$prevLink = '<a '.
'href="'.$modx->makeUrl($slides[$s]['id']).'" '.
'title="'.htmlspecialchars($slides[$s]['pagetitle']).'" '.
'class="'.$classPrefix.'prevLink">'.
$prevLinkOn.
'</a>';
}
// Otherwise, if this isn't the last page and we haven't done so, reset the next link
else if ( $seenCurrent && !$nextReset && $slides[$s]['id'] != $modx->documentObject['id'] )
{
$nextLink = '<a '.
'href="'.$modx->makeUrl($slides[$s]['id']).'" '.
'title="'.htmlspecialchars($slides[$s]['pagetitle']).'" '.
'class="'.$classPrefix.'prevLink">'.
$nextLinkOn.
'</a>';
$nextReset = TRUE;
}
// Number line -------------------------------------------------------------
// Add slide number to number line ($s + 1) - as link if not current page
if ( $slides[$s]['id'] == $modx->documentObject['id'] && !$currentPageLinked )
{
$currentSlideArray[] = '<span class="'.$classPrefix.'currentSlide">'.($s+1).'</span>';
}
else
{
// Determine slide link class
$slideNumberClass = ($slides[$s]['id'] == $modx->documentObject['id']) ?
'currentSlide': (($seenCurrent) ? 'afterSlide' : 'beforeSlide');
// Make slide link
$slideLink = '<a '.
'href="'.$modx->makeUrl($slides[$s]['id']).'" '.
'title="'.htmlspecialchars($slides[$s]['pagetitle']).'" '.
'class="'.$classPrefix.$slideNumberClass.'">'.
($s+1).
'</a>';
if ( $slides[$s]['id'] == $modx->documentObject['id'])
{
$currentSlideArray[] = $slideLink;
}
else if ( $seenCurrent )
{
$afterSlideArray[] = $slideLink;
}
else {
$beforeSlideArray[] = $slideLink;
}
}
}
// Determine how many before and after links we can have - if not all (0)
if ( $numberLineMax )
{
// Determine maximum number of before/after slides to show
$beforeQty = floor(.5*($numberLineMax-1)) + max(0, (floor(.5*($numberLineMax-1)) - count($afterSlideArray)) );
$afterQty = floor(.5*($numberLineMax-1)) + max(0, (floor(.5*($numberLineMax-1)) - count($beforeSlideArray)) );
// Adjust link arrays
while ( $beforeSlideArray && count($beforeSlideArray) > $beforeQty )
{
array_shift($beforeQty);
}
while ( $afterSlideArray && count($afterSlideArray) > $afterQty )
{
array_pop($afterQty);
}
}
// Merge before, current, and after arrays
$numberLineArray = array_merge($beforeSlideArray,$currentSlideArray,$afterSlideArray);
// Add separators
$numberLine = implode($numberLineSeparator,$numberLineArray);
// Set placeholders
$modx->setPlaceholder($prevPh,$prevLink);
$modx->setPlaceholder($nextPh,$nextLink);
$modx->setPlaceholder($numberLinePh,$numberLine);
return '';
?>
It uses placeholders for the previous, next, and number line navigation bits. And has a few configurable options. I made it for a presentation I’ll be giving our University webmasters on MODx in May. I wanted a new template that was presentation style (read: PowerPoint substitute) to show how MODx can easily flex to suit your needs. The content is FAR from established, but you can
see the navigation if you like. In this case I used the horses as previous/next
mystery meat navigation. Not great design, but for the situation, I could be a little hokey. Anyway, you’re welcome to use the snippet if you like.
Of course this only applies if your docs are in the same folder.