Blog Sections Open

Counting Only Visible Children with ChildCounter

If a menu counter should ignore hidden resources, include the hidemenu condition in the document query instead of counting every child indiscriminately.

The default ChildCounter logic may count every matching child, even those hidden from menus. If the count is meant for navigation or category lists, that can be misleading.

Original snippet idea

$davailable = $modx->getChildIds($docid, $depth);
$dcount = $modx->getDocuments($davailable, $published, 0, 'id', 'isfolder='.$isfolder);
return count($dcount);

Improvement

Add the hidemenu=0 condition to the document query so hidden resources no longer inflate the count.

Recommendation

Whenever a counter is used in menus, ask whether it should represent all resources or only visible ones. The answer changes how users interpret the number.

Newer post

Using antispam and Captcha with JotX

If antispam seems to “do nothing”, verify what fields it actually injects and whether your template or theme is hiding them.

Older post

Building Dependent Filters in Evolution CMS

Dependent filters are easiest to reason about when each selection narrows the available values for the next step instead of trying to solve everything in one giant query.