Forum

Thread tagged as: Question, Blog

Showing sub-categories

I have a 2 sets of categories for my blog. blog - > news + subcategories & blog - > contest + subcategories

I try to use perch_blog_categories() to display sub-categories only from "news" and on other page sub-categories only from contest. But every time I try diffrent solutions found here on forum, I always get full list of categories.

Using code below, it always shows me categories from contest also.

perch_blog_categories(array(
'set' => 'blog/news/'
));

perch_blog_categories(array(
'set' => 'news'
));

Will be thankful for any suggestions, I pretty sure it is something simple I'm missing here. Thanks.

Maciej Pieńczewski

Maciej Pieńczewski 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is this blog-specific, or should you be using perch_categories() ?

Drew, it does not need to be blog-specific, but using perch_categories( )

perch_categories([
   'set' => 'blog/news/',
]);

gives me the same results as perch_blog_categories(), all categories are displayed.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is that a valid set slug? It doesn't look like it is.

I have copied this one from admin panel (path in categories) twice to make sure it is correct :) but still the same results.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like a category path, not a set slug. A set slug example would be blog, not blog/news/

I have created new Set called "Test" I can display only sub-categories for Test - set using

perch_categories([
    'set' => 'test',
]);

but how can I achieve this for blog categories?

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_categories([
 'set' => 'blog', 
]);

Looks like my misunderstanding. Then one more time, I have a Set called Blog and in Blog I have to 2 main categoires News and Contest. These categories have sub-categories. I want to display sub-categories only for News

I think this should work, but it does not. It gives me empty results.

perch_categories([
   'set' => 'blog',
   'filter' => 'catPath',
   'match' => 'contains',
   'value' => 'blog/news/'
]);

Sometimes it's easiest to add <perch:showall /> to the template which in this case is /perch/templates/categories/category.html so you will know what fields are available, and what the values are of those fields.

This will make troubleshooting a bit easier if you know what's happening at runtime...

category.html (default template shown with showall example added)

<perch:before><ul></perch:before>
<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:showall />

<perch:after></ul></perch:after>

Thanks Robert for suggestion, I know catPath exists in category template. But I do not know how I can filter this categories This one gives me empty results.

perch_categories([
'set' => 'blog',
'filter' => 'catPath',
'match' => 'contains',
'value' => 'blog/news/'
]);

Thanks Robert! Your suggestion was very helpful :) I achived it by filtering it by catParentID

                            perch_categories([
                            'set' => 'blog',
                            'filter' => 'catParentID',
                            'match' => 'eq',
                            'value' => '19'
                            ]);