We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3004
    • 21 Posts
    No, I’m afraid includeFolders=1 doesn’t include the children of a folder in the navigation - not yet anyway. When I get around to it I’ll add that functionality.

    -Aaron
      • 6316
      • 92 Posts
      Aaron, thanks for the update, although it didn’t fix the bug with symbols: whenever I put ← and →, it just stops working sad
        • 29703
        • 217 Posts
        Quote from: PMS at Mar 04, 2008, 05:19 PM

        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>'
              );
           
        }
        ?>


        Yes! I was getting parse errors but this has fixed it perfectly.

        One question. . .

        Is it possible for the previous and next links to be there even when you run out of documents and for it to link back round to the start again? So the previous button takes you to the most recent document when it reaches the end and vice versa?

        Cheers.
          • 22851
          • 805 Posts
          Hi thehen.

          You could customise the snippet to do that. Here is a rough idea for how you might do it. Lets call it a wrap functionality.

          First you need a parameter to decide whether wrapping will be on or off, with the default being off.
          if ( !isset( $wrap) )
          {
            $wrap = false;
          }
          


          Next you need to find the code that normally generates the previous item placeholder. There are if/else-if blocks there to handle the various cases. You need to insert an elseif block at the appropriate place (not at the very end) that says, "if there is no previous document and wrap is set to on then..." and in there you need to paste the code for the last item placeholder from further down the page. So, it will look something like...

          ...}
          elseif ($prev <= 0 && $wrap)
          {
             $PJN_prevPlaceHolder =
               '<a href="[~'
               . $my_array[$limit]['id']
               . '~]">'
               . $lastText
               . '</a>';
          }
          elseif (...
          


          Likewise, when there is no next document and wrap is on, you need to display the first item placeholder:

          ...}
          elseif ($next > $limit && $wrap)
          {
             $PJN_nextPlaceHolder =
                 '<a href="[~'
               . $my_array[1]['id']
               . '~]">'
               . $firstText
               . '</a>';
          }
          elseif (...
          


          I think that should be it. It’s obviously completely untested, but you could give it a try. If it works, feel free to post it back here.

          Cheers.
            YAMS: Yet Another Multilingual Solution for MODx
            YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
            Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
            • 17723
            • 221 Posts
            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
              Lucas from AroundCyprus.net
              • 33719
              • 33 Posts
              embarrassed
              Hello,

              I’m trying to order elements by pub_date but it does not work ... it seems it’s because the modx’s request don’t order elements
              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;  
              (I added the pub_date field to debug).
              In phpmyadmin, the order by has no effect at all (but has if i remove the GROUP BY)

              Is there a way to get over that modx bug ? (is it a known bug ?)

              MySQL: 5.0.51a
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                It’s a well-known bug in that version of MySQL.
                  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
                  • 33719
                  • 33 Posts
                  oki,

                  I was’nt thinking that it could be due to mysql :/ But I found that’s a mysql bug, as you said sottwell.

                  Sorry for the pollution :/
                  Thanks
                    • 32853
                    • 1 Posts
                    I’m having the same problem on my side, is there a solution for this?
                    Would be grateful !

                    Quote from: lx at Sep 06, 2008, 03:44 PM

                    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

                    Thanks,
                    XeyefeX
                      • 22851
                      • 805 Posts
                      Hi there.

                      I have just created a templatable snippet called Navigator that allows you to make prev, next and up links. It’s fully templatable and will transcend the levels of the menu system if you want too. There are some things that PrevJumpNext does that this wont do however. ’Jump’ is one of them. Ordering by something other than menuindex is also currently not supported, since it is really designed for navigating menu systems.

                      It can be downloaded from the repository and there is a support thread in the forums.

                      It’s not thoroughly tested yet, so if anyone wants to take it for a spin, please feel free.

                      Paul
                        YAMS: Yet Another Multilingual Solution for MODx
                        YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                        Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.