Forum

Thread tagged as: Question, Blog

Filtering Categories by Blog Section

Is there a way to show a list of categories which have only been used on posts within a specified Blog section (not category set as I can only use Blog as the set).

Sarah Evans

Sarah Evans 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

There isn't currently.

Ok thanks.

I'm trying to think of a way around it...

If I use categories with subcategories can I filter on the catSlug using the categories as a way of 'sectioning' the subcategories?

Does a subcategories category appear in the Slug? I don't think it does, so perhaps I've answered my own question

Drew McLellan

Drew McLellan 2638 points
Perch Support

It doesn't have to appear in the slug - that's up to you, but you'll need to know how to piece together the category path if you don't have it in the slug.

Hi Drew,

Apologises for the delay, I'm just getting my head back into this project.

To create a list of categories with 'monkey' in the path would I do something like this?


<?php perch_blog_categories(array( 'template' => 'category_listings.html', 'filter' => 'catSlug', 'match' => 'eq', 'value' => 'monkey', )); ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, I think so. Is that not working?

No it doesn't.

EDIT:

Actually sorry I may not have been very clear. I'm looking to sort by the Categories Path so say there are some categories like:

blog/animal/monkey

blog/animal/panda

I want to get all the categories with the 'animal' path, is that possible?

            <?php
                perch_blog_categories(array(
                    'template' => 'category_listings.html',
                    'filter' => 'catSlug',
                    'match' => 'eq',
                    'value' => 'animal',

                ));
            ?>

Drew McLellan

Drew McLellan 2638 points
Perch Support

Neither of those examples have a slug that is equal to (eq) 'animal', which is why it's not matching.

I think the type of match you want is contains.

Is filtering by catSlug going to look at the Path?

To get all categories that contains 'animal' I'd do this?


<?php perch_blog_categories(array( 'template' => 'category_listings.html', 'filter' => 'catSlug', 'match' => 'eq', 'value' => 'animal', )); ?>

I feel I could use Category templates to help me create a way of filtering what I want here but I'm having trouble using it. Whenever I try to change the Category Template or Set Template it just reverts back to Set for each

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_blog_categories(array(
    'template' => 'category_listings.html',
    'filter' => 'catSlug',
    'match' => 'contains',
    'value' => 'animal',
));

That's what I was suppose to paste into my previous post rather than repeating eq again.

That doesn't return anything.

Debug:

SELECT main.* , COALESCE(cc.countValue,0) AS `count.blog.post` FROM perch2_categories main LEFT OUTER JOIN perch2_category_counts cc ON cc.catID=main.catID WHERE 1=1 AND (catSlug REGEXP '[[:<:]]animal[[:>:]]') AND setID='1' AND (cc.countType='blog.post' OR cc.countType IS NULL) AND cc.countValue > 0 ORDER BY catTreePosition ASC
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is this your first category set?

Yes it's the blog one.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I would expect that to work. I'll try to have a look at it in the morning.

Thanks Drew.

The Set template and Category template is on 'Set' and I can't change it (it reverts back after saving). I'm not sure if that would have anything to do with it but thought it was worth a mention.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you using Perch 2.8.2?

Yes I am, but I think I had the category template problem before

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, we're looking into this.