Forum

Thread tagged as: Question, Problem, Configuration

How to pull items in based on categories?

I am using perch_content_custom and using a 2 page list and details set up. Everything is working fine, now I am using categories and I want to be able to pull the items that are in specific categories.

I have a category.php page with the following code on it.

<?php perch_content_custom('Products', array(
        'page'=>'/product.php',
        'template' => 'product_listing.html',
        'category' => perch_get('cat'),
)); ?>

Now I want to be able to pull specific items based on a query string like category.php?cat=food and that page should load all the items that are in the food category. But this current set up is not returning anything to the screen. Any ideas as apparently I am doing something wrong when it comes to categories.

Thanks for the help in advance.

-Brandon

Brandon Livengood

Brandon Livengood 1 points

  • 6 years ago

Is it because the categories page is by default expected to be the index page of a categories subdirectory (example.com/categories/index.php)? What path does the category set you're looking to pull in have in the categories app? Could be that you need to match this with a more specific 'category' bit in the array. Something like 'category' => perch_get('food/'.perch_get('cat').'/'),

I am using the default category and set templates that come with categories template folder if that helps?

Have you looked at: https://docs.grabaperch.com/video/v/portfolio-with-categories/ - I think this would be a similar setup to what you're trying to do. At the bottom of that page look at the category.php:

<?php    
    if (perch_get('cat')) {
      perch_category(perch_get('cat'),array(
        'template'=>'category_single.html'
    ));
    perch_content_custom('Portfolio', array(
      'template' => 'portfolio_listing.html',
      'page'=>'/portfolio.php',
      'category' => perch_get('cat'),
    ));
    } else {
      perch_categories();
    }
    ?>

Have you set the category template so point at the right page and template?

EDIT Whoops I should of read that better. The below post looks like it might be the key

I might have to defer to Drew and Rachel's expertise on this one in that case, Brandon. I must admit, that every category I've used is particular to its own list/detail page (a bit like blog categories are tied to the blog) so I always end up following the solution I was given last year: https://forum.grabaperch.com/forum/08-21-2014-categories-in-subdirectory

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the current issue? This is a big hard to follow after the fact!

Sorry we got it sorted I had to put the category path in and it worked.

I think Brandon sorted it. Clive Walker posted something on the Slack channel, which worked in the way Brandon was after. Basically he needed to specify the set in the category bit of the array: 'category' => 'set/'.perch_get('cat'),