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`]]
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)
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`]]
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`!]
It only gives me one post output (the second article/ID). Strange.
Uups.... remove &display=`1`
updated the snippet above. Sorting out the latest of each container didn’t work as it should.