We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9359
    • 128 Posts
    Hi everybody,
    Sorry, I have another question ...
    I can easily count how many results I get a call to ditto? Or better a quick way to get the number of children of a resource .. I assume with a snippet?!
    can someone help me please?

    thx

    [ed. note: fabryshock last edited this post 15 years ago.]
      "Destiny is not a matter of chance, it's a matter of choice"
      • 9359
      • 128 Posts
      i have found a snippet, but did'nt work in Evo:
      getChildCount:

      <?php
      $count = 0;
      $parent = isset($parent) ? (integer) $parent : 0;
      if ($parent > 0) {
      $criteria = array(
      'parent' => $parent,
      'deleted' => false,
      'published' => true,
      );
      $count = $modx->getCount('modResource', $criteria);
      }
      return (string) $count;
      ?>

      someone can tell me how to change it for Evo?
      many thx
        "Destiny is not a matter of chance, it's a matter of choice"
        • 9359
        • 128 Posts
        In Evo appear this error when i try the snippet:
        Fatal error: Call to undefined method DocumentParser::getCount() in /var/www/isola/manager/includes/document.parser.class.inc.php(814) : eval()'d code on line 10
          "Destiny is not a matter of chance, it's a matter of choice"
          • 4041
          • 788 Posts
          <?php
          /*
            usage
           [ !snippet? &parent=`XX`! ]  or [ !snippet! ]
          */
          
          $parent = isset($parent) ? (integer)$parent : $modx->documentObject['id'];
          $child_count = $modx->db->getRecordCount( $modx->db->select( 'id',$modx->getFullTableName('site_content'), 'parent="'.$parent.'" AND published="1"' ) );
          
          $output = $child_count !='' ? $child_count : '';
          return $output;
          ?>

            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 36592
            • 970 Posts
            If you need that total number of retrieved documents after Ditto call, you might be able to use [+total+] placeholder.
            See here -> http://ditto.modxcms.com/tutorials/pagination.html
              • 9359
              • 128 Posts
              Hi,
              many thx at all!!
              the snippet of breezer work great!!

                "Destiny is not a matter of chance, it's a matter of choice"
                • 29201
                • 239 Posts
                Anyway we could modify this to allow for multiple parents? Exp. [!DittoCounter? &parent=`15,66,68`! ]

                Quote from: fabryshock at Sep 23, 2011, 08:24 AM
                i have found a snippet, but did'nt work in Evo:
                getChildCount:

                <!--?php
                $count = 0;
                $parent = isset($parent) ? (integer) $parent : 0;
                if ($parent --> 0) {
                $criteria = array(
                'parent' => $parent,
                'deleted' => false,
                'published' => true,
                );
                $count = $modx->getCount('modResource', $criteria);
                }
                return (string) $count;
                ?>

                someone can tell me how to change it for Evo?
                many thx
                  • 13428 ☆ A M B ☆
                  • 1,031 Posts
                  <?php
                  /**
                   * Count children of a comma separated list of document ids
                   * usage
                   *[!getChildCount? &parent=`x,y,z`!]  or [!getChildCount!]
                   */
                  
                  $parents = isset($parents) ? array_map('intval', explode(',', $parents)) : array($modx->documentObject['id']);
                  
                  $childCount = 0;
                  foreach ($parents as $parent) {
                      $childCount += $modx->db->getRecordCount(
                          $modx->db->select(
                              'id',
                              $modx->getFullTableName('site_content'),
                              'parent=' . $parent . ' AND published=1 AND deleted=0'
                          )
                      );
                  }
                  return ($childCount) ? $childCount : '';
                  
                  [ed. note: Jako last edited this post 12 years, 5 months ago.]
                    • 13428 ☆ A M B ☆
                    • 1,031 Posts
                    <?php
                    /**
                     * Count children of a comma separated list of document ids
                     * usage
                     *[!childCount? &parent=`x,y,z`!]  or [!childCount!]
                     */
                    
                    $parents = isset($parents) ? array_map('intval', explode(',', $parents)) : array($modx->documentObject['id']);
                    
                    $childCount = $modx->db->getRecordCount(
                        $modx->db->select(
                            'id',
                            $modx->getFullTableName('site_content'),
                            'parent IN (' . implode(',' . $parents) . ') AND published=1 AND deleted=0'
                        )
                    );
                    return ($childCount) ? $childCount : '';