Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// We're grabbing each category and filtering the 'Properties' region using that category - if the property count is 0, we don't pass that category to the output.
// This method does produce a database query for each category, so I would run it with debug switched on to see if makes an impact for your setup or not.
<?php perch_categories(['set'=>'area','sort'=>'catTitle','sort-order'=>'ASC','each'=>function($item) {
if (PerchUtil::count(perch_content_custom('Properties',
['skip-template'=>true, 'category'=>$item['catPath']])) > 0) return $item; }]
); ?>
// You do have to make a slight change to the category template with this though - an example using the default category.html template:
<perch:if id="catDepth" match="neq" value="0">
<li style="margin-left: <perch:category id="catDepth" type="hidden" />0px;"> <h4><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></h4> <perch:category id="catSlug" type="slug" for="catTitle" suppress="true" /> <perch:category id="desc" type="textarea" label="Description" editor="markitup" markdown="true" size="s" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.