Single Page List Detail With Category Filters
I'm trying to put together a single list-detail page listing attractions with a category listing in the sidebar that would filter the list of attractions by the categories they belong to, which is what I'm currently stuck on.
The code for the list-detail page looks like so:
<?php
perch_content_create('Attractions', array(
'template' => 'attractions/attraction.html',
'multiple' => true,
'edit-mode' => 'listdetail',
));
?>
<?php
if (perch_get('s')) {
echo'';
// Detail mode
perch_content_custom('Attractions', array(
'template' => 'attractions/attraction.html',
'filter' => 'slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1,
));
} else {
// List mode
echo'<div class="container-fluid">
<div class="row center-xs">
<div class="col-xs-12 col-sm-10 col-md-4 col-lg-3" style="margin-bottom:2rem;">
<h1 class="pageTitle">Attractions</h1><span></span>
</div>
</div>
</div>';
echo'<div class="container-fluid"><div class="row"><div class="col-xs-12 col-sm">';
echo'<p>Categories</p>';
if (perch_get('cat')) {
perch_category(perch_get('cat'),array(
'template'=>'categories/attraction_category.html'
));
perch_content_custom('Attractions', array(
'template' => 'attractions/attraction_listing.html',
'page'=>'/attractions',
'category' => perch_get('cat')
));
} else {
perch_categories();
}
echo'</div>';
perch_content_custom('Attractions', array(
'template' => 'attractions/attraction_listing.html',
));
echo'</div></div>';
}
?>
The listing and detailing works fine, and the listing of categories shows up, but when I click on a category link, it shows an empty content area with header and footer. The debug message on that page is as follows:
Debug Message
SELECT * FROM perch2_pages WHERE pagePath='/attractions/index.php' LIMIT 1
SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/attractions/index.php' OR regionPage='*' ORDER BY regionPage DESC
Using template: /templates/search/search-form.html
SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Attractions' AND (regionPage='/attractions/index.php' OR regionPage='*')
SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=37 AND idx.itemRev=66)) AND ((idx.indexKey='slug' AND idx.indexValue='downtown-bloomington/')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC LIMIT 0, 1
Using template: /templates/content/attractions/attraction.html
Using sub-template: /templates/content/attractions/attraction_maps.html
SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
My guess on my problem is that while there is a listing function for the categories, there is no detail function, so it doesn't show anything. I'm not sure how to get to that from where I'm at though. I'd want to use the same attraction_listing
template for listing the attractions within a category.
I'm on 2.8.6.
What does your URL look like when you filter by category?
On the page:
/attractions/historical-places/
and in the template<a href="/<perch:category id="catPath" />">
Should it have a query string?
Are you using Runway?
No, regular perch.
Do you have rewrite rules in place for those paths?
I do.
Ok, so rewrites
historical-places
to?cat=historical-places
?If so, you'll need to add the set name to the front to create a full category path.
It's rewriting the attractions slug
for each individual attraction in the list-detail setup in a subfolder called attractions. Not the categories, at least that's not my intention. Though looking at it that may be what it's doing.
So the link to the categories in the attractions set needs to look like
href="attractions/<perch:category id="catPath" />"
?You don't need to change the link. You just need to make sure you use the set name to form a full category path when filtering on the category.
Okay, so that goes into the second function?
I still need to put something in the detail mode section of the code for the filtered result to show up on the page, right?
Did that bit work?
Can you list out the states the page displays in?
No, that did not work. Thinking about it, I don't need a detail section for the categories because it's filtering the list mode.
The page displays in list mode with a list of categories in a sidebar, and detail mode. Here's the link to the dev site if it's helpful in visualizing: https://vc.garyriverson.com/attractions/
So:
And category links which filter on the list of attractions, if that counts as a third mode.
Like this?
Yes, that's right.
So the framework of your code should be something like:
Okay, the categories list is now persistent, but the listing by category still does not appear.
This is what I've got:
Maybe you'll see something in the templates that I'm missing, so here they are:
Attractions from selected category
Listing
Detail
Which part is your listing by category?
I've been trying to use the second one, the Listing template.