We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6649
    • 25 Posts
    Hey

    As everyone knows the document ID gets plastered to each new document you create - however - if I delete one, is there a way of replacing that last number? So create doc, number 6, dont like it, delete, create doc, number 7, delete it ... now there is a gap ...

    The other reason I need this so badly is that I use a small next and previous snippet to jump between the pages, so I get to page 5, then made mistakes all the way to 15!!!!!

    Is there a way to permanatly delete pages? Even if you delete them from the manager you can still get to the live pages by typing in the DocID in the address bar - so they haven’t really been deleted?!?!

    A little bit of help would be hugely loved!

    D
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      If you are dependent on that snippet, never delete a document. Just edit it to be whatever you want.

      Deleted documents show a strikethrough; click on the trash icon at the top of the Document Tree to remove them from the database.

      If you are still finding deleted documents, clear the cache.

      The numbers are automatically assigned by the database; you cannot re-use them (unless you laboriously go into the database and give an unused ID number to a newly-created document). Be aware that several things are tied in to that number in the database, particularly TV values.
        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
        • 6649
        • 25 Posts
        Thanks for the reply

        I only have the snippets and the content tag, so maybe I don’t have to worry about the TVs?

        I am aware that the snippet NextJumpPrev can do what would be ideal, but I can never get it to work. I have a link for a button <a> tag and want it to go into the ’href’ element and obviously go to the next viable page. However, I can’t seem to crack it.

        Can you show me with an example?

        Thanks rather a lot!

        D
          • 27708 MODX Staff
          • 2,502 Posts
          Quote from: Dave01 at Apr 10, 2008, 08:57 AM

          Is there a way to permanatly delete pages? Even if you delete them from the manager you can still get to the live pages by typing in the DocID in the address bar - so they haven’t really been deleted?!?!

          A little bit of help would be hugely loved!

          Documents that are deleted but not purged will only show up to Managers who are logged in. So sure they will show up in your prev next until you purge the document tree.

          Another thought is to use some other document reference to retrieve the prev/next such as pub date or title etc.

          Cheers,

          Jay
            Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
            • 6649
            • 25 Posts
            Jay

            Thanks very much, didn’t realise they only show to logged in manager. The only problem with using pub date or title, is the buttons are embedded into the template, and are obviously repeated page by page, hence why the ID + 1 seemed like a good idea.

            Can anyone advise on how to change the numbers via PHPMyAdmin or where there is a good article/thread

            Cheers, D
              • 13577
              • 302 Posts
              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.
                Standard Disclaimer
                I could be totally wrong.
                • 6649
                • 25 Posts
                Cheers Jay - talk about timing!

                Let me just get this straight - I just have to place the placeholders in the <a> tags right? Or is there more I have to do?

                But cheers for letting me copy that, I will be using it and I think you should definitely put it in the repository my friend!

                I changed the DocID for the pages, and it was surprisingly easy using PHPMyAdmin, everything is back to normal now. I will give you some feedback once I have used it and let you know.

                Thanks again Jay
                  • 27708 MODX Staff
                  • 2,502 Posts
                  Not sure what you are thanking me for but okay.

                  I will say to MODx newbs IT IS NEVER A GOOD IDEA TO CHANGE THE DOC IDs in the database as it can screw up the way things function. People do it because they get so hung up on the little numbers in the tree but they are just ids. As suggested you can use the directory order number or other methods to organize prev nexts.

                  Anyway. All the best on your project.

                  Cheers,

                  Jay
                    Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                    • 6649
                    • 25 Posts
                    Jay

                    I was thanking you for your help mate!

                    D
                      • 27708 MODX Staff
                      • 2,502 Posts
                      I would think that you should be thanking Jared for his snippet? But I love to help.

                      Cheers,

                      Jay
                        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub