Forum
How to display 'similar projects' based on their category on a detail page
Hi Forum! I may not be searching for the right terms but I cannot find anything about this online so here goes:
I have a list, detail and category page set up for a projects section on a website, all working fine. What I would like to do is display similar projects, i.e. list of projects from the same category at the bottom of the detail page. How do I do this?
Let me know if you need any of my code but as I say it's a pretty bog standard set up but I just can't find what I'm looking for anywhere else.
Take a look here...
https://docs.grabaperch.com/perch/categories/filtering/
Unfortuntely, I've tried that but it's not filtering them out. It's still displaying all categories. Ideally I want it to be able to tell what category the project on the detail page is assigned to and display other projects from the same category below it. I'll have to keep looking. Thanks though!
Emily, how are you populating the
category
variable?Posting your code is the best way for us to help you troubleshoot... otherwise were just throwing out ideas...
I'm not sure what you mean by category variable but here's my code.
This is my index page, I've got a list of categories as a subnav across the top.
This is my detail page, this code isn't working. The detail displays fine but the category code below displays all categories instead of the one the project belongs to.
This is my category page code. This work fine.
Are you passing the category on the url?
I want to say no because I don't actually know what that means. I'm a super newbie to categories.
EXAMPLE: www.thisIsMySuperDuperDomain.com/myFancyDirectory?cat=myFancyCategoryPassedOnURL
Are you passing category on the url something like this??
Oh hang on, yes then I have: www.thisIsMySuperDuperDomain.com/projects/category?cat=projects/category That's a bit of a weird url right?
The code examples you post are expecting the
category
to be part of your url...perch_get('cat')
will be populated with the value you pass on the URL as?cat=projects/project1
Ah ok, I think I understand what you are saying. I'm actually trying to pass the category on the detail page which has the url www.thisIsMySuperDuperDomain.com/projects/detail?s=project-name so it isn't going to work on that page because it isn't the category page it's the detail page.
you can add to the URL query string so
www.thisIsMySuperDuperDomain.com/projects/detail?s=project-name&&cat=projects/project1
What I was getting at with my original question is
perch_get('cat')
is expecting to find cat=something on the URL, and if it isn't there you would be getting results your experiencing.Oh yes, so it's looking at the URL to find which category to pass. I see! Thank you so much for your help, and patience! That change to the url has worked.