We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28033
    • 925 Posts
    Is there either a document variable (like how you can grab the published date of a page), or a snippet that can grab the total number of published documents?

    I want to have a page that lists the total number of pages created, among other things.
      My Snippets
      -> PopUpChunk v1.0
      • 10487 MODX Staff
      • 1,535 Posts
      This, in a snippet, will give the total number of published pages:
      <?php
      $count = $modx->db->getValue('SELECT COUNT(id) FROM ' . $modx->getFullTableName('site_content') . ' WHERE published=1');
      return $count['COUNT(id)'];
      ?>


      Hope that helps,
      Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 28033
        • 925 Posts
        I’m getting 6 when I run that (both cached and uncached). I commented it out so the HTML doesn’t parse, but you can see the number if you check any of site’s pages’s source code.

        I have *much* more than six pages of published content, so why is it giving that value?
          My Snippets
          -> PopUpChunk v1.0
          • 10487 MODX Staff
          • 1,535 Posts
          That’s a bit bizarre undecided What happens if you run the SQL statement directly via PHPMyAdmin (or equivalent):
          SELECT COUNT(id) FROM modx_site_content WHERE published=1;

          Do you get the proper count using that?
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 28033
            • 925 Posts
            Quote from: garryn at Jun 28, 2008, 08:53 PM

            That’s a bit bizarre undecided What happens if you run the SQL statement directly via PHPMyAdmin (or equivalent):
            SELECT COUNT(id) FROM modx_site_content WHERE published=1;

            Do you get the proper count using that?

            I don’t have access to phpMyAdmin due to the host I’m being hosted on forcing only one person to have cPanel/PMA rights (i.e., you have to pay extra for more accounts).

            When I do see my host on MSN, I’ll ask him to run that to see what the result is.

            EDIT: Wait, does that check *every* document, or only in a specific area? Because I think I have six or so files in a /site "folder" in my MODx document tree...
              My Snippets
              -> PopUpChunk v1.0
              • 7231
              • 4,205 Posts
              Slight tweak and it seems to be working:
              <?php
              $count = $modx->db->getValue($modx->db->select('COUNT(*)', $modx->getFullTableName('site_content'), 'published=1'));
              return $count;
              ?>


              What I changed; getValue() returns a string, not an array. and I used the modx dbapi to build the select statement (but it worked the other way as well).
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don&#39;t know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 28033
                • 925 Posts
                Now it shows 658, which seems right. Thanks for the quick fix. smiley
                  My Snippets
                  -> PopUpChunk v1.0