Skip to content

Instantly share code, notes, and snippets.

@clivewalker
Last active October 12, 2020 10:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clivewalker/12bf481ac53b334bf72afd0dfb164324 to your computer and use it in GitHub Desktop.
Save clivewalker/12bf481ac53b334bf72afd0dfb164324 to your computer and use it in GitHub Desktop.
// 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:before><ul></perch:before>
<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" />
</li>
</perch:if>
<perch:after></ul></perch:after>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment