Forum
Excluding unused categories in a category list?
Is there a way of excluding categories that have not been checked/ticked by the editor?
I'm creating a property site where there's 20+ towns/areas which won't all be used at any one time. (List and details pages with categories).
So ideally I need a list of all the area/town categories that have only been checked/ticked by the editor. (A short category list rather the whole list rather where 75% of the category links would return noresults
.
I believe Perch blog has this behaviour.
Hello David,
You may be able to achieve this with
perch_content_custom()
(and perch_template()) instead ofperch_categories()
.I can't get your example to work. I can get a list of all the categories ticked (from the list of the list and details page)...
HTML
PHP
Template
However, I need this list to...
For example in a property list of four properties cats ticked with area1, area2, area,3 area1. I need to remove the duplicates.
Then I'm there. Any pointers where I'm going wrong?
I think my example above is actually flawed.
I thought of a better approach. I think something like the following should work:
Your
page.php
:And your template
templates/categories/your_template.html
doesn't need to includeperch:categories
pair tag:Hopefully this works! If not, perhaps others can come up with a better approach.
Another approach to take is the following:
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 (it shouldn't really - it's basically the same query being repeated, so the query optimiser should handle it). You do have to make a slight change to the category template with this though - an example using the default
category.html
template:The addition is the
catDepth
if
statement surrounding the main detail.Great solution, Duncan! I predict this will come in handy one day.