Forum

Thread tagged as: Problem

Filtering Categories

I've been following the Portfolio with Categories Video tutorial here: https://docs.grabaperch.com/video/v/portfolio-with-categories/

I've not been able to get the categories filtering page working where it shows a list of items in that category from the category slug. It always displays the list of categories (else)

category.php:

   <?php    
    if (perch_get('cat')) {
      perch_category(perch_get('cat'),array(
        'template'=>'category_single.html'
    ));
    perch_content_custom('Product Area', array(
      'template' => 'product_listing.html',
      'page'=>'/products.php',
      'category' => perch_get('cat'),

    ));
    } else {
      perch_categories();
    }
    ?>

My categories are set up as: 'products/metal-detectors/' which has the url or /category/products/metal-detectors/ I have the suspicion that something is going wrong here?

Debug:

Debug Message
SELECT * FROM perch2_pages WHERE pagePath='/category.php' LIMIT 1
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/seo.html
SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1
SELECT main.* FROM perch2_categories main WHERE 1=1 ORDER BY catTreePosition ASC
Using template: /templates/categories/category.html
Sarah Evans

Sarah Evans 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the value of ?cat when it comes through to your page?

/products/metal-detectors/

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's odd, because it doesn't look like it's making it through:

SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1

Is that tested or expected? What does this output?

<?php echo perch_get('cat'); ?>

<?php echo perch_get('cat'); ?>

This doesn't output anything.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah ha - progress.

What does your rewrite rule look like? (Or are you using Runway?)

Normal Perch

Rewrites:

RewriteRule ^products/([a-zA-Z0-9-/]+)$ /details.php?s=$1 [L]
RewriteRule ^category/([a-zA-Z0-9-/]+)$ /category.php?s=$1 [L]

so URLs for category pages are: /category/products/metal-detectors/

Drew McLellan

Drew McLellan 2638 points
Perch Support

So according to this:

/category.php?s=$1

you're setting the matched value as ?s= on the query string. Therefore this:

perch_get('cat')

should be

perch_get('s')