We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8489
    • 90 Posts
    Is it possible with getResources to count and output the number of children the container has under it?

    Like: container-name (22)

    Thanks
      • 22840
      • 1,572 Posts
        • 8489
        • 90 Posts
        I tried that but can’t get it to work :-{
        Also I don’t want to output all the file names but only the name of the container and the number of files in it.
          • 22840
          • 1,572 Posts
          Quote from: Expanism at Apr 18, 2011, 09:49 AM

          I tried that but can’t get it to work :-{
          Also I don’t want to output all the file names but only the name of the container and the number of files in it.
          It does work as I have it on my site and it just counts the children and outputs a number.

          How have you tried it ?


            • 8489
            • 90 Posts
            What I have tried is a container called "Test" has id 43 and contains 5 files

            Test
            - FileA
            - FileB
            - FileC
            - FileD
            - FileE

            I tried the following

            Snippet:

            <?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;
            ?>


            On the page:

            [[getResources? &parents=`43` &showHidden=`1` &tpl=`count` &limit=`30` &depth=`0`]]

            tpl "count":

            <a href="[[~[[+id]]]]">[[+pagetitle]]</a> ([[getChildCount? &parent=`[[+id]]`]])

            Outputs on the page:

            FileA (0)
            FileB (0)
            FileC (0)
            FileD (0)
            FileE (0)

            But I would like it to output:

            Test (5)
              • 22303 MODX Staff
              • 10,725 Posts
              Then you need to use the parent of 43, not 43 as the parent... huh
                • 8489
                • 90 Posts
                huh How could I make it the parent of 43?
                  • 22303 MODX Staff
                  • 10,725 Posts
                  What is the parent of 43?
                    • 8489
                    • 90 Posts
                    I have it working now with:

                    [[getResources? &parents=`2` &resources=`-44,-45,-46,-47,-48,-49,-50,-51,-52` &showHidden=`0` &tpl=`count` &limit=`30` &depth=`0`]]

                    I have to set all the other containers under parent 2 with &resources=`-44,-45,... to exclude them.
                    It would be great if it was possible to have the other containers under 2 excluded automatic?

                    Well it is working now smiley Thanks for the replys!
                      • 8489
                      • 90 Posts
                      Perhaps UltimateParent can do the trick?