Forum

Thread tagged as: Question
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is this supposed to be your list of categories?

perch_categories(array('category' => 'attractions/'.perch_get('cat')));

Yes, that is.

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_categories() produces a list of categories. It looks like you're then trying to filter it by categories categorised as the current category, which is as confusing as it sounds.

I think you probably want to filter it by set.

perch_categories([
    'set' => 'attractions',
]);

Okay, I've got that in there now and I've gone through the whole page setup again. For a while the category URLS were trying to go to /attractions/attractions/historical-places for example, but changing the link in the category template to this fixed that.

<a href="/attractions/<perch:category id="catSlug" type="slug" for="catTitle"/>">

Now when I click on a category, the URL 404's instead of showing nothing, which may or may not be progress. What else am I missing?

My revised list-detail page looks like this:

$match_found = false;
// Create region for attractions
perch_content_create('Attractions', array(
 'template'   => 'attractions/attraction.html',
 'multiple'    => true,
 'edit-mode' => 'listdetail',
));

if (perch_get('cat')) {
      // Show selected category and description
     perch_category(perch_get('cat'),array(
        'template'=>'categories/attraction_single_category.html',
        'set' => 'attractions',

    )); 
  // Show attractions from selected category

     perch_content_custom('Attractions', array(
      'template' => 'attractions/attraction_listing.html',
      'page' => '/attractions/index.php',
      'category' => perch_get('cat'),


     )); 
    $match_found = true;
}

if (perch_get('s')) {
     // Detail mode
  perch_content_custom('Attractions', array(
      'template' => 'attractions/attraction.html',
      'filter' => 'slug',
      'match' => 'eq',
      'value' => perch_get('s'),
      'count' => 1,
 ));
    $match_found = true;
}

if (!$match_found) {
    // Show categories list
  perch_categories([
    'set' => 'attractions',
    'template' => 'attraction_category.html',
      ]);
  // List mode
  perch_content_custom('Attractions', array(
      'template' => 'attractions/attraction_listing.html',

     )); 
   }

LIst of Categories

<a href="/attractions/<perch:category id="catSlug" type="slug" for="catTitle"/>"><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></a>

Listing

<h3><a href="/attractions/?s=<perch:content id="slug" type="slug" />"><perch:content id="attrPlaceName" type="text" /></a></h3>

<perch:categories id="attrCategory" label="Category" set="attractions" divider-before="Categories" required="true">
<a class="attrCatLink" href="<perch:category id="catPath" />"><perch:category id="catTitle" /></a>
</perch:categories>

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the URL that 404s, and what rewrite rule do you have in place for it?

The list of categories link 404s. This one:

<a href="/attractions/<perch:category id="catSlug" type="slug" for="catTitle"/>"><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></a>

Rewrite looks like:

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

Drew McLellan

Drew McLellan 2638 points
Perch Support

So a URL like /attractions/historical-places doesn't match?

That very URL will 404, yes.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so it's not getting as far as your Perch code and anything I can help with. You'll need to check your rewrite rules.

Okay. I'll be back when I get that sorted out in the hope that it magically solves all problems.

I ended up splitting it into multiple pages which resolved my issues.