Last active
October 12, 2020 10:00
-
-
Save clivewalker/12bf481ac53b334bf72afd0dfb164324 to your computer and use it in GitHub Desktop.
Excluding unused categories with Perch CMS. From http://forum.grabaperch.com/forum/01-06-2018-excluding-unused-categories-in-a-category-list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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