Here’s a modified version of the PrevJumpNext snippet. I have attempted to modify the output so that it can be used in XHTML 1.0 Transitional (and probably Strict with very minor modifications, it at all) documents served as application/xhtml+xml. I haven’t tested it extensively, but it appears to work fine with the latest versions of Safari, Mozilla and Internet Explorer. The interface is the same as the original version. Only the output is different.
<?php /** * * ************************** * Snippet: PrevJumpNextXHTML * By: Jeroen Bosch modded by OncleBen31 and modified again by PMS * Date: Mar 2008 * version: 0.3 (based on the PrevJumpNext v0.3) * ************************** * * Function: * Generates buttons to navigate between document of a same directory. * Very handy on top or bottom of each individual newspost/log item * Highly configurable. It can display : * - 'Prev' and 'Next' button with or without document titles * - 'first' and 'last' document. * - 'Index' link to parent folder * - a DropList to jump quickly to a document * * You can use a classic use of the snippet or use the paginate option * which allow you to use PlaceHolders to personnalise your navigation * buttons : * - [+PJN_first+] : the first document * - [+PJN_prev+] : the previous document * - [+PJN_jump+] : the droplist to jump to the selectionned document * - [+PJN_index+] : the link to retern to the index page * - [+PJN_next+] : the next document * - [+PJN_last+] : the last document * * There is many option which can allow you to sort the document, set * the text to use with the element, etc ... : * - sortBy : Sort items by? 'menuindex' or 'id' or 'createdon', etc... (default createdon) * - sortHow : Sort items How? 'ASC' or 'DESC' (default ASC) * - displayTitle : how 'prev' and 'next' or display document titles (default true) * - displayFixed : Show 'first' and 'last' (default false) * - usePlaceHolder : Set at true to use PlaceHolder : [+PJN_first+] , [+PJN_prev+] , [+PJN_jump+] , [+PJN_index+] , [+PJN_next+] , [+PJN_index+] (default false) * - useJump : Replace the Index link by the Jump dropList when NOT using the PlaceHolders (default false) * - indexDocumentID :Specifie the document to go using the link "index". (by default its is the parent ID) * - displayNoPrevNext : set to true to display a text when there is no Prev or no Next element (default false) * - noPrevNextText : Text to display if there is no Prev or no Next element :(default "-") * - indexText : Text to use with the link "index" (default "Index") * - jumpText : Text to use with the dropdown list (jump function) (default :"Please Select") * - firstText : Text to use with the link "First" (default "<< First") * - prevText : Text to use with the link "Prev" when $displayTitle is set to false (default "< Prev") * - nextText : Text to use with the link "Next" when $displayTitle is set to false (default "Next >") * - lastText : Text to use with the link "Last" (default "Last >>") * * * The output use <div> and <span> to allow you to CSS the buttons * * * Enjoy and don't esitate to ask new features * Exemples : * * [[PrevNext? sortBy=menuindex &sortHow=ASC &displayTitle=true]] * Or * [[PrevJumpNext_New? &sortBy=`pub_date` &usePlaceHolder=true &indexDocumentID=`84` &firstText=`Première` &lastText=`Dernière` &prevText=`Précédente` &nextText=`Suivante` &indexText=`Liste des News` &jumpText=`Accès rapide` &displayNoPrevNext=true &noPrevNextText=`C'est le bout`]] * with this place holder in the document [+PJN_first+] [+PJN_prev+] [+PJN_jump+] [+PJN_index+] [+PJN_next+] [+PJN_last+] */ /* TODO - Limiter la longeur de la liste - Ajouter la phrase article n° X sur Total - Faire la traduction - Ajouter un préfix lors de l'utilisation des titres pour Prev et Next */ # Settings # Sort items by? 'menuindex' or 'id' or 'createdon' if(!isset($sortBy)) { $sortBy = 'createdon'; // default in NewsListing-snippet } # Sort items How? 'ASC' or 'DESC' if(!isset($sortHow)) { $sortHow = 'ASC'; // default in NewsListing-snippet } # Show 'prev' and 'next' or display document titles? if(!isset($displayTitle)) { $displayTitle = true; } # Show 'first' and 'last' if(!isset($displayFixed)) { $displayFixed = false; } // Parameters added By OncleBen31 # Set at true to use PlaceHolder : [+PJN_first+] , [+PJN_prev+] , [+PJN_jump+] , [+PJN_index+] , [+PJN_next+] , [+PJN_index+] if(!isset($usePlaceHolder)) { $usePlaceHolder = false; } # Replace the Index link by the Jump dropList when NOT using the PlaceHolders if(!isset($useJump)) { $useJump=false; } # Specifie the document to go using the link "index". (by default its is the parent ID) if(!isset($indexDocumentID)) { $indexDocumentID=$modx->documentObject['parent']; } # set to true to display a text when there is no Prev or no Next element if(!isset($displayNoPrevNext)) { $displayNoPrevNext=false; } # Text to display if there is no Prev or no Next element if(!isset($noPrevNextText)) { $noPrevNextText="-"; } # Text to use with the link "index" if(!isset($indexText)) { $indexText="Index"; } # Text to use with the dropdown list jump function if(!isset($jumpText)) { $jumpText="Please Select"; } # Text to use with the link "First" if(!isset($firstText)) { $firstText="<< First"; } # Text to use with the link "Prev" when $displayTitle is set to false if(!isset($prevText)) { $prevText="< Prev"; } # Text to use with the link "Next" when $displayTitle is set to false if(!isset($nextText)) { $nextText="Next >"; } # Text to use with the link "Lastt" if(!isset($lastText)) { $lastText="Last >>"; } // // The code: // // Get the parent ID $parentid = $modx->documentObject['parent']; // maybe this solves it all, but I'm not sure. // (re)set the $id variable to the one of this document. $id = $modx->documentIdentifier; // select the other members in this folder -- See: NOTE 1 $fields='id,pagetitle,isfolder'; // what fields do you want to know $children = $etomite->getActiveChildren($parentid, $sortBy, $sortHow, $fields); // the number of selected documents //$limit = $modx->recordCount($children); $limit = count($children); // set $y to zero $y = 1; // sorting the documents, giving them a sequential and searchable index foreach ($children as $child) { $my_array[$y] = $child; if ($my_array[$y]['id']==$id) { $current=$y; // The current page has number $y in the array } $y++; } $prev = $current-1; $next = $current+1; // ### Construction oh the elements // First item $PJN_firsPlaceHolder = '<a href="[~' . $my_array[1]['id'] . '~]">' . $firstText . '</a>'; // Prev item if($prev > 0 && !$displayTitle ) { $PJN_prevPlaceHolder = '<a href="[~' . $my_array[$prev]['id'] . '~]">' . $prevText . '</a>'; } elseif($prev > 0 && $displayTitle) { $PJN_prevPlaceHolder = '<a href="[~' . $my_array[$prev]['id'] . '~]">' . $my_array[$prev]['pagetitle'] . '</a>'; } elseif($prev <= 0 && $displayNoPrevNext) { $PJN_prevPlaceHolder = $noPrevNextText; } // Jump item $PJN_jumpPlaceHolder = '<form action="" name="jump1" style="display:inline;">' . '<select name="myjumpbox" onchange="javascript:if (this.selectedIndex != 0) {var ops=this.getElementsByTagName(\'option\'); var url=ops[this.selectedIndex].getAttribute(\'value\'); if (url) {location.href=url;};}">' . '<option selected="selected">' . $jumpText . '</option>'; foreach ($my_array as $my_page) { $PJN_jumpPlaceHolder .= '<option value="[~' . $my_page['id'] . '~]" >' . $my_page['pagetitle'] . '</option>'; } $PJN_jumpPlaceHolder .= '</select></form>'; // Index item $PJN_indexPlaceHolder = '<a href="[~' . $indexDocumentID . '~]">' . $indexText . '</a>'; // Next item if($next <= $limit && !$displayTitle) { $PJN_nextPlaceHolder = '<a href="[~' . $my_array[$next]['id'] . '~]">' . $nextText . '</a>'; } elseif($next <= $limit && $displayTitle) { $PJN_nextPlaceHolder = '<a href="[~' . $my_array[$next]['id'] . '~]">' . $my_array[$next]['pagetitle'] . '</a>'; } elseif($next > $limit && $displayNoPrevNext) { $PJN_nextPlaceHolder = $noPrevNextText; } // Last item $PJN_lastPlaceHolder = '<a href="[~' . $my_array[$limit]['id'] . '~]">' . $lastText . '</a>'; // #### Output commputing modded by Oncleben31 if (!$usePlaceHolder) { // Here starts the output $output = ''; $output .= '<div class="PJN_Menu">'; if($displayFixed) { $output .= $PJN_firsPlaceHolder . ' < '; } $output .= $PJN_prevPlaceHolder . ' | '; if($useJump) { $output .= $PJN_jumpPlaceHolder . ' | '; } else { $output .= $PJN_indexPlaceHolder . ' | '; } $output .= $PJN_nextPlaceHolder; if($displayFixed) { $output .= ' > ' . $PJN_lastPlaceHolder; } $output .= '</div>'; return $output; } else { // Set PlaceHolder $modx->setPlaceholder( 'PJN_first' , '<span class="PJN_Menu"><span class="PJN_First">' . $PJN_firsPlaceHolder . '</span></span>' ); $modx->setPlaceholder( 'PJN_prev' , '<span class="PJN_Menu"><span class="PJN_Prev">' . $PJN_prevPlaceHolder . '</span></span>' ); $modx->setPlaceholder( 'PJN_jump' , '<span class="PJN_Menu"><span class="PJN_Jump">' . $PJN_jumpPlaceHolder . '</span></span>' ); $modx->setPlaceholder( 'PJN_index' , '<span class="PJN_Menu"><span class="PJN_Indext">' . $PJN_indexPlaceHolder . '</span></span>' ); $modx->setPlaceholder( 'PJN_next' , '<span class="PJN_Menu"><span class="PJN_Next">' . $PJN_nextPlaceHolder . '</span></span>' ); $modx->setPlaceholder( 'PJN_last' , '<span class="PJN_Menu"><span class="PJN_Last">' . $PJN_lastPlaceHolder . '</span></span>' ); } ?>
if ( !isset( $wrap) )
{
$wrap = false;
}
...}
elseif ($prev <= 0 && $wrap)
{
$PJN_prevPlaceHolder =
'<a href="[~'
. $my_array[$limit]['id']
. '~]">'
. $lastText
. '</a>';
}
elseif (...
...}
elseif ($next > $limit && $wrap)
{
$PJN_nextPlaceHolder =
'<a href="[~'
. $my_array[1]['id']
. '~]">'
. $firstText
. '</a>';
}
elseif (...
SELECT DISTINCT sc.pub_date, sc.id,sc.pagetitle,sc.isfolder,sc.hidemenu FROM `gps-modx`.`modx_site_content` sc LEFT JOIN `gps-modx`.`modx_document_groups` dg on dg.document = sc.id WHERE sc.parent = '2' AND sc.published=1 AND sc.deleted=0 AND (sc.privateweb=0) ORDER BY sc.pub_date ASC;
Hello,
Please advice me. In total pages I get always one page more that there are in my folder.
So If there are 5 documents in my folder I get 6 as a total pages, when i have 6 documents in my container I get 7 as total pages.
Please advice me what can be the problem.
I use PJN 0.4 ver with a simplest call [!PrevJumpNext!]
regards
lx