We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42639
    • 9 Posts
    Bit of a newbie question here, but it there a simple way to list the templates used by the site and the number of published and unpublished pages each template uses?

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      There's no simple way, but this will do it:

      [[TemplateReport]]



      <?php
      /* TemplateReport snippet */
      /* TemplateReport snippet */
      $templates = $modx->getCollection('modTemplate');
      
      $output = '<h3>Template Report</h3>';
      $output .= "\n<ul>";
      
      $published = array('published' => '1');
      $unpublished = array('published' => '0');
      foreach ($templates as $template) {
          $id = $template->get('id');
          $name = $template->get('templatename');
          $c1 = $modx->newQuery('modResource');
          $c1->where(array(
              'published' => '1',
              'template'  => $id,
          ));
          $numPublished = $modx->getCount('modResource', $c1);
      
           $c2 = $modx->newQuery('modResource');
           $c2->where(array(
               'published' => '0',
               'template'  => $id,
           ));
           $numUnpublished = $modx->getCount('modResource', $c2);
      
           $output .= "\n" . '<li><b>' . $name . '</b>';
              $output .= "\n<ul>";
                 $output .= "\n" . '   <li>Published resources: ' . $numPublished . '</li>';
                 $output .= "\n" . '   <li>Unpublished resources: ' . $numUnpublished . '</li>';
              $output .= "\n</ul>";
              $output .= "\n</li>";
      }
          $output .= "\n</ul>";
      
      return $output;
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 42639
        • 9 Posts
        Bob - that's genius. Thanks very much - a really useful script.
          • 3749
          • 24,544 Posts
          I'm glad I could help. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting