Forum

Thread tagged as: Problem, Add-on-development

Categories in subdirectory

I'm having trouble with the new Categories app.

My portfolio page lives in a subdirectory /portfolio/index.php with the detail page being /portfolio/case-study. I've created the category page at /portfolio/category/ to mirror the way my blog app deals with categories (/blog/category/name).

I'm working through the tutorial and am hitting a wall when trying to get a category to appear, filtered by the ?cat= query string. In the Perch control panel I've set up a category called design in a set called portfolio. I've added this category to a case study. So far so good.

I've amended the link to the category using /portfolio/category/<perch:category id="catSlug" instead of id="catPath" as I didn't want the trailing slash that catPath generates, and I want the url to be /portfolio/category/design rather than /portfolio/category/portfolio/design

My category page has this code:

  <?php
    if (perch_get('cat')) {
      echo('1');
      perch_category(perch_get('cat'));
    } else {
      echo('2');
      perch_categories();
    }
  ?>

The numbers are being echoed so I know it's sort of working. The straightforward perch_categories() works too (though I think I'll have to filter this by the portfolio set somehow, as it currently returns all sets).

So I'm doing something wrong, but I don't know what. Can you help?

My mod_rewrite looks like this, in case that's useful:

  RewriteRule ^portfolio/category/([a-zA-Z0-9-]+)$ /portfolio/category.php?cat=$1 [L]
  RewriteRule ^portfolio/category/?$ /portfolio/category.php [L]
  RewriteRule ^portfolio/page/([a-zA-Z0-9-]+)$ /portfolio/?page=$1 [L]
  RewriteRule ^portfolio/([a-zA-Z0-9-/]+)$ /portfolio/case-study.php?s=$1 [L]
Martin Underhill

Martin Underhill 5 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't get the category by its slug, it needs to be by the path.

Add portfolio back on:

perch_category('portfolio/'.perch_get('cat').'/');

Sorry for the late reply, Drew. Thanks– works a treat :)

Thought to mention why I didn't reply sooner– I didn't get a notification email. Seems you can only request them when replying to a thread, not posting the original.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can request them from your grabaperch.com account as a blanket setting.

Sweet! I've turned them on now :)