Hi,
I would like to count the number of documents inside a container and display that number
Would be nice if ditto could do that but I did not find a way to do that
Thx for your help
Yep but if I use ditto to display the a list of containers it would be nice to display the number of documents within Ditto.
I will have look and see if I can get it to work with ditto
Thx
Any luck on this one? I’m looking for the same solution within Ditto. My goal is as table with the names of some containers and the number of documents within those containers.
I think, thererfor I am! But what I am, and why...?
Quote from: OpenGeek at May 22, 2008, 02:27 PM
<?php
// initialize and get the number of children for a particular parent
$childCount = 0;
if ($children = $modx->getChildIds($parent, $depth)) {
$childCount = count($children);
}
// do something with $childCount or just return it
return $childCount;
?>
And then call it in your content, e.g. to get just the immediate child count for the current document:
[!GetChildCount? &parent=`[*id*]` &depth=`1`!]
Is there a way to NOT count the containers, only plain documents, within these script?
I think, thererfor I am! But what I am, and why...?
Thanks for trying, but I’m sorry, it doesn’t work. I followed your instructions, and there are no errors, the script only gives an empty result. Nothing.
Here is my Ditto-call: <ul>
[[Ditto?parents=`369` &depth=`2` &tpl=`Familiy-list-tpl` &display=`all` &sortBy=`pagetitle` &sortDir=`ASC` &extenders=`count-childs` ]]
</ul>
And here is my template: <li>[+pagetitle+] - [+count-childs+]</li>
Here is the result:
<ul>
<li><em<Polygonum</em> L. - </li>
<li><em>Achillea millefolium</em> - </li>
<li><em>Achillea</em> L. - </li>
<li><em>Alchemilla glomerulans</em> - </li>
<li><em>Alchemilla</em> Bus. - </li>
<li><em>Alopecurus magellanicus</em> - </li>
<li><em>Alopecurus</em> L. - </li>
Mabye I do something wrong.
I think, thererfor I am! But what I am, and why...?
Did you set up the extender correctly?
1. go to snippets/ditto/extenders and create a new file count-childs.extender.inc.php
2. paste the code above
also
did you install the ChildrenCount snippet?
I made a mistake
Use
<li>[+pagetitle+] - [+counterCh+]</li>