Forum
How to filter by category with Perch Runway?
I've setup a collection called Projects and to this I've added a category set called Project-set
I've added perch:categories id="project-set" to my collection template. When I click the link, I've simplified the template. I get a message Sorry, that page could not be found.
<perch:categories id="project-set" label="Project categories" set="project-set" required="true">
<a href="/category/<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>
</perch:categories>
I've created a /category page and I have the following PHP on it:
if (perch_get('cat')) {
perch_category(perch_get('cat'),array(
'template'=>'category_single.html'
));
} else {
perch_categories();
}
When I visit /category page directly I see a list of all the categories using the default template, as expected.
I have a feeling I have to do something with routing and tokens, can you tell me what I'm doing wrong please?
Is this a typo?
Whoops. Yes. Changed it.
Is the reason it's not working something to do with routing? If so, what would I write to make it work?
Hi
Still stuck on this.
Using a Perch Collection with Categories, how do I filter content based on a category?
On my home page I have a collection called Projects
The Projects collection uses a template that includes perch:categories. This is the bit of the template that outputs a link to my category page:
On my category page I have this PHP
When I click on the category link, the if statement is skipped and the else part is displayed, using the default category template. I'd like to be able to display the category_single.html template when the category link is clicked.
I can't see what I'm missing? Hope you can help.
Hi
I'm still trying to get this to work. I've watched the Portfolio with Categories video, as it has a bit in it about filtering categories, but using the code above (based on the video) I can't get it to work?
What am I doing wrong? I've had something similar to this working with Perch but can't seem to get it working with Perch Runway, I'm sure I'm missing something obvious - I just can't see it.
Drew / Rachael
Any chance you could take a look at this?
How do I use
perch_get('cat')
with Perch Runway? I've used the PHP below on a Perch website and it works:But the same doesn't seem to work with Perch Runway. I have a feeling it might be related to URL patterns / Routing - but I don't know. I'd really appreciate some guidance on this.
Yes - what's the value of
cat
at that point? Is it a full category path? Or just a category slug?It'd be a full category path. You'd get to by clicking:
Have you tested what value you're getting back into the page?
Is this what you mean? This is the message when the URL pattern is ** /category**
This is what I see when I set the URL pattern to /category/project-set/[slug:cat]
You've got no page arguments coming in. What route have you set up for this?
I updated the previous post. The URL pattern is /category/project-set/[slug:cat]
Can you give an example of the URL?
https://local-demo-runway/category/project-set/construction/
It's a Perch Runway site, running locally via MAMP Pro
When I click on the link
The PHP doesn't work, neither the if or the else statements outputs anything, but the rest of the page displays.
Any further thoughts on this? I've pulled everything into one post, hopefully it will make it clearer.
Would you set it up any differently?
home has a
perch_collection
that contains a template with this link:Clicking this link (on the home page) outputs this URL:
This is the URL pattern for the category page:
On the category page I have this PHP:
The page loads, but the PHP doesn't trigger.
Here's the debug message:
Anyone else having this problem? Trying to filter categories from within a
perch_collection
You need to use a full category path, not just the category slug as you currently have.
Ah, ok
How do I add the full category path to this:
Is there a docs page I can refer to?
Done!
I added the full category path to
perch_category
Thanks for pointing me in the right direction!