We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28341
    • 43 Posts
    Is it possible to print out children of a number of selected parents instead of outputting all? Like so -

    [[Ditto? &parents=`50,51,49,52` &display=`1` &orderBy=`createdon DESC`]]
      • 19369
      • 1,098 Posts
        • 28341
        • 43 Posts
        Isn’t it typical that I missed out that one...
        Hm. But it doesn’t work. What could I be missing? This is my exact setting:

        [[Ditto? &documents=`50,51,49,52` &display=`1` &orderBy=`createdon DESC` &tpl=`home-article` &lastClass=`last`]]

        (They all have children, and I’m only looking for displaying the first child of each parent)
          • 4172
          • 5,888 Posts
          Quote from: staffan.estberg at Jun 17, 2010, 06:50 AM

          Isn’t it typical that I missed out that one...
          Hm. But it doesn’t work. What could I be missing? This is my exact setting:

          [[Ditto? &documents=`50,51,49,52` &display=`1` &orderBy=`createdon DESC` &tpl=`home-article` &lastClass=`last`]]

          (They all have children, and I’m only looking for displaying the first child of each parent)

          you can set 4 ditto-calls:

          [[Ditto? &parents=`50` &display=`1` &orderBy=`createdon DESC`]]
          [[Ditto? &parents=`51` &display=`1` &orderBy=`createdon DESC`]]
          [[Ditto? &parents=`49` &display=`1` &orderBy=`createdon DESC`]]
          [[Ditto? &parents=`52` &display=`1` &orderBy=`createdon DESC`]]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 28341
            • 43 Posts
            Sort of did that before, I was trying to make the code more efficient wink
            But if there’s no other solution I guess that’s the way to go.
              • 4172
              • 5,888 Posts
              perhaps a little bit more efficient:

              create this snippet:

              <?php
              // [[getlatestchilds? &parents=`1,2,3,4`]]
              if ( isset ($parents))
              
              {
              $parents=explode(',',$parents);
              $ids = array ();
              $table = $modx->getFullTablename('site_content');
              foreach ($parents as $parent){
              
                  $query = 'select id as contentid,parent from '.$table.' where parent='.$parent.'  order by createdon DESC LIMIT 1';
                  $rs = $modx->db->query($query);
                  
                  while ($row = $modx->db->getRow($rs))
                  {
                      $ids[] = $row['id'];
                  }	
              }    
                  return implode(',', $ids);
              }


              and call Ditto like that:

              [!Ditto? &documents=`[[getlatestchilds? &parents=`50,51,49,52`]]` &orderBy=`createdon DESC` &tpl=`home-article` &lastClass=`last`!]

                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 28341
                • 43 Posts
                It only gives me one post output (the second article/ID). Strange.
                  • 4172
                  • 5,888 Posts
                  Uups.... remove &display=`1`
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 28341
                    • 43 Posts
                    Thanks!
                      • 4172
                      • 5,888 Posts
                      updated the snippet above. Sorting out the latest of each container didn’t work as it should.
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!