We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21560
    • 145 Posts
    I apologize for the errors wink Usually I do test it better, but this was rather rushed. Birthday and stuff.

    Thanks for the fixes!
      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
      • 13730
      • 149 Posts
      I like your BasicNav snippet, it’s very simple.

      I get your BasicNav snippet from the «Modx Add-Ons Zone» and installed it via the revolution package management module.

      I noticed that it is not your new version. I simply replace your old php code by the new but, it is not working.

      Is it possible to add your new version of BasicNav in the «Modx Add-Ons Zone».

      Thank you very much
        • 9550
        • 123 Posts
        just tried this snippet, but i’m not getting anything output with the following call:
        [[!basicNav? &sortBy=`menuindex` &sortDir=`ASC`]]


        same blank output if I try just [[!basicNav?]]

        the pages I’m testing this snippet on are at the 2nd depth off web root inside a container. there are about a dozen fellow children pages, all are published and none are set to be hidden from the menu.

        Anyone know what’s I’m doing wrong?

        Also, is this snippet the best practice way in revolution for adding simple Next/Previous links to navigate between pages in a given container?


          • 8609
          • 607 Posts
          Quote from: featherodd at Apr 04, 2011, 10:42 PM

          just tried this snippet, but i’m not getting anything output with the following call:
          [[!basicNav? &sortBy=`menuindex` &sortDir=`ASC`]]


          same blank output if I try just [[!basicNav?]]

          Anyone know what’s I’m doing wrong?


          Snippet calls are case sensitive. You want BasicNav, NOT basicNav as you have it.

          [[!BasicNav? &sortBy=`menuindex` &sortDir=`ASC`]]
            • 9550
            • 123 Posts
            einsteinsboi: tried that first. then switched to basicNav (camelcase like getResources). nothing with either. just tried it like BasicNav again. Still nothing.
              • 8609
              • 607 Posts
              Quote from: featherodd at Apr 04, 2011, 11:24 PM

              einsteinsboi: tried that first. then switched to basicNav (camelcase like getResources). nothing with either. just tried it like BasicNav again. Still nothing.

              Odd. It should be BasicNav. Have you tried adding the &placeholder=`1` parameter and then using [[!+basicnav]] where you want the navigation to appear?

              Also, make sure BasicNav is not just downloaded into your addons but is also installed. I’ve made that mistake once smiley
                • 9550
                • 123 Posts

                it’s installed...

                so you mean to first call something like:
                [[!BasicNav? &sortBy=`menuindex` &sortDir=`ASC` &placeholder=`1`]]


                and then call [[!+basicnav]] ??

                  • 9550
                  • 123 Posts
                  Woah, weird. that worked. ok, so now my snippet call is basically:

                  [[!BasicNav? &sortBy=`menuindex` &sortDir=`ASC` &placeholder=`1`]][[!+basicnav]]


                  which is then giving me...

                  <div class="nav"><div></div><div><a title="Entry to Purgatory" class="prev" href="exhibitions/nicholas-frennette/entry-to-purgatory.html">></a></div><div><a title="Pimples Pickings" class="next" href="exhibitions/nicholas-frennette/pimples-pickings.html"><</a></div><div><a title="Sunday Afternoon In The Cornfeild" class="last" href="exhibitions/nicholas-frennette/39.html">>></a></div></div>


                  huh... do you know if there is a cleaner way to create next / previous page links in Revolution? something like [[~[[*prev]]]] / [[~[[*next]]]]
                    • 9550
                    • 123 Posts
                    MichaelvanLaar: just tried your revised code and it works like a dream! thanks man!! Waaay better not to HAVE to use a placeholder and having documentation is darn helpful.

                    One quick suggestion: classes for the div wrappers, otherwise they’re a bit awkward to style, say if you wanted to float "next" left and "previous" right inside a sidebar or something like that.
                      • 7253
                      • 97 Posts
                      Hi,
                      I added a couple of extra parameters to this snippet:

                      &showHidden        If true, will show Resources regardless if            Default: 0
                                         they are hidden from the menus.
                      
                      &outerClass        Class to be applied to the outer div                  Default: nav
                      


                      <?php
                      /* BasicNav by Nimja.com
                         (enhanced a little bit by michael-van-laar.de)
                      
                      Snippet call (example with all optional parameters):
                      [[!BasicNav? &sortBy=`publishedon` &sortDir=`ASC` &currentPosition=`[[*id]]` &placeholder=`0` &hideFirst=`0` 
                      &hidePrev=`0` &hideNext=`0` &hideLast=`0` &firstTxt=`<<` &prevTxt=`<` &nextTxt=`>` &lastTxt=`>>`]]
                      
                      Placeholder (if &placeholder=`1` is used in the snippet call):
                      [[!+basicnav]]
                      
                      Snippet call and placeholder MUST be called uncached, otherwise pages in the middle would not know when a new last page is added.
                      
                      
                      Parameters (all optional) in detail :
                      
                      &sortBy            Field containing the sorting order criterion          Default: publishedon
                      
                      &sortDir           Sorting order (ASC or DESC)                           Default: ASC
                      
                      &currentPosition   ID of the resource which marks the current position   Default: (ID of current resource)
                                         in the page tree level you want to get the next and
                                         previous resource from.
                                         YOU ONLY NEED THIS PARAMETER IF YOU WANT TO "BREAK
                                         OUT" OF THE CURRENT FOLDER.
                                         
                                         Example:
                                   
                                         In the following resource structure (page tree) you want to include links
                                         to the next and previous project on every "project detail" page.
                                         In this case you have to set &currentPosition to [[*parent]]. By doing this
                                         the next and previous links on every "project detail" page don't refer to
                                         the next and previous "project detail" page (as they normally would), but to
                                         the next and previous "project" page.
                                 
                                         + Project overview
                                         |
                                         +--+ Project 1
                                         |  +--- Project detail page 1.1
                                         |  +--- Project detail page 1.2
                                         |
                                         +--+ Project 2
                                         |  +--- Project detail page 2.1
                                         |  +--- Project detail page 2.2
                                         |
                                         +--+ Project 3
                                            +--- Project detail page 3.1
                                            +--- Project detail page 3.2
                      
                                         In concrete terms:
                                         Placing the snippet and placeholder call
                                             [[!BasicNav? &currentPosition=`[[*parent]]`]] [[!+basicnav]]
                                         on page "Project detail page 2.1" would generate one link to page
                                         "Project 1" and one link to page "Project 3".
                      
                      &showHidden        If true, will show Resources regardless if            Default: 0
                                         they are hidden from the menus.
                      
                      &outerClass        Class to be applied to the outer div                  Default: nav
                      
                      &placeholder       Output is stored in placeholder (see above)           Default: 0 (= FALSE)
                      
                      &hideFirst         "First link" will never be displayed. (Useful if      Default: 0 (= FALSE)
                                         only next and previous links should be displayed.)
                      
                      &hidePrev          "Previous link" will never be displayed. (Useful if   Default: 0 (= FALSE)
                                         only first and last links should be displayed.)
                      
                      &hideNext          "Next link" will never be displayed. (Useful if       Default: 0 (= FALSE)
                                         only first and last links should be displayed.)
                      
                      &hideLast         "Last link" will never be displayed. (Useful if        Default: 0 (= FALSE)
                                         only next and previous links should be displayed.)
                      
                      &firstTxt         Link text of "first link"                              Default: <<
                      
                      &prevTxt          Link text of "previous link"                           Default: <
                      
                      &nextTxt          Link text of "next link"                               Default: >
                      
                      &lastTxt          Link text of "last link"                               Default: >>
                      
                      */
                      
                      
                      // ---- Default Values forced.
                      
                      $sortBy = !empty($sortBy) ? $sortBy : 'publishedon';
                      $sortDir = !empty($sortDir) ? $sortDir : 'ASC';
                      $placeholder = !empty($placeholder) ? $placeholder : FALSE;
                      $cur = !empty($currentPosition) ? $currentPosition : $modx->resource->id;
                      $showHidden = !empty($showHidden) ? $showHidden : 0;
                      $outerClass = !empty($outerClass) ? $outerClass : 'nav';
                      
                      $hideFirst = !empty($hideFirst) ? $hideFirst : FALSE;
                      $hidePrev = !empty($hidePrev) ? $hidePrev : FALSE;
                      $hideNext = !empty($hideNext) ? $hideNext : FALSE;
                      $hideLast = !empty($hideLast) ? $hideLast : FALSE;
                      
                      $firstTxt = !empty($firstTxt) ? $firstTxt : '<<';
                      $prevTxt = !empty($prevTxt) ? $prevTxt : '<';
                      $nextTxt = !empty($nextTxt) ? $nextTxt : '>';
                      $lastTxt = !empty($lastTxt) ? $lastTxt : '>>';
                      
                      // ---- Actual code 
                      
                      //Get the parents (and verify)
                      $curResource = $modx->getObject('modResource',$cur);
                      $parent = $curResource->get('parent');
                      if (empty($parent)) {
                        return 'No parent?';
                        exit;
                      }
                      //Get the children.
                      $criteria = $modx->newQuery('modResource');
                      $criteria->where(array(
                         'parent' => $parent,
                         'hidemenu' => $showHidden,
                      ));
                      $criteria->sortby($sortBy,$sortDir);
                      $children = $modx->getCollection('modResource',$criteria);
                      
                      $first = NULL;
                      $prev = NULL;
                      $next = NULL;
                      $last = NULL;
                      
                      $seen = FALSE;
                      $now = FALSE;
                      foreach ($children as &$child) {
                        //Check if this is the current child.
                        $now = ($child->id == $cur);
                        if ($now) $seen = TRUE;
                        
                        //First one is only set once.
                        if (!$hideFirst && !$seen && empty($first)) $first = $child;
                        //Prev is set until we meet our current.
                        if (!$hidePrev && !$seen) $prev = $child;
                        //Next is set once directly after the current.
                        if (!$hideNext && $seen && empty($next) && !$now) $next = $child; 
                        //Set after we've seen stuff.
                        if (!$hideLast && $seen && !$now) $last = $child;
                      }
                      //Disable certain things at times.
                      if (!$hideFirst && ($first == $prev)) $first = NULL;
                      if (!$hideLast && ($last == $next)) $last = NULL;
                      
                      $result = '<div class="'.$outerClass.'">';
                      if (!$hideFirst) $result .= empty($first) ? '' : '<div><a href="[[~'.$first->id.']]" class="first" title="'.$first->pagetitle.'">'.$firstTxt.'</a></div>';
                      if (!$hidePrev) $result  .= empty($prev)  ? '' : '<div><a href="[[~'.$prev->id.']]" class="prev" title="'.$prev->pagetitle.'">'.$prevTxt.'</a></div>';
                      if (!$hideNext) $result  .= empty($next)  ? '' : '<div><a href="[[~'.$next->id.']]" class="next" title="'.$next->pagetitle.'">'.$nextTxt.'</a></div>';
                      if (!$hideLast) $result  .= empty($last)  ? '' : '<div><a href="[[~'.$last->id.']]" class="last" title="'.$last->pagetitle.'">'.$lastTxt.'</a></div>';
                      $result .= '</div>';
                      
                      if ($placeholder) {
                        $modx->setPlaceholder('basicnav', $result);
                        return;
                      } else {
                        return $result;
                      }
                      ?>
                      


                      This version also doesn’t output empty div’s for empty items - i.e. if you’re at the first item, it doesn’t output <div></div> for the previous item, it now doesn’t output anything. Maybe this should be an option?