We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10357
    • 573 Posts
    Hi,

    is there any snippet available that returns the number of document in a particular folder?

    cheers,
    G
      • 33337
      • 3,975 Posts
      With special thanks to Mark Kaplan! our Ditto Guru smiley

      #::::::::::::::::::::::::::::::::::::::::
      # Snippet name: DocCount
      # Short Desc: Displays # of documents in a specified folder 
      # Created By Mark Kaplan ([email protected])
      #
      # Date: April 3, 2006
      #
      # Usage: [[DocCount? &startID=`1`]]
      #::::::::::::::::::::::::::::::::::::::::
      
      $resourceparent = isset($startID) ? $startID : $modx->documentIdentifier; 
      $resource = $modx->getActiveChildren($resourceparent, 'id', 'ASC', $fields='*');
      $num = count($resource);
      return $num;
      


      Have fun!
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 10357
        • 573 Posts
        woohoo! grin thank you !
          • 22303 MODX Staff
          • 10,725 Posts
          Ok, why would you query the database for this when you can get count($modx->getChildIds($resourceparent, 1)) much more quickly, and without an extra db hit? Just curious...
            • 25663 MODX Staff
            • 12,272 Posts
            Really think about an option to show only pages that are published and only set to be in the menu ... that way you can get an idea of the number of "real" content pages. (e.g., excludes 404 pages, thank you pages, etc.)
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 33337
              • 3,975 Posts
              Here comes a MODx Guru! laugh ...

              I don’t know actually whats in there and why, but its an old snippet Mark has written for 0.9.1, i think you are talking about new API? in 095? right? if yes can you please add it where it should go.. wink

              Thanks Jason!
                Zaigham R - MODX Professional | Skype | Email | Twitter

                Digging the interwebs for #MODX gems and bringing it to you. modx.link
                • 10357
                • 573 Posts
                so is there a better way i should be doing this?