Forum
How to handle blog sub-categories with Runway?
Hi there, I'm almost finished reconfiguring my blog to Runway.
I'm coming up against some issues with my archive of sub-categories.
In my post.html template, I display the parent and sub-cat for a given post, as follows:
<perch:categories id="categories" set="blog" label="Categories" display-as="checkboxes">
<a href="/blog/category/<perch:category id="catSlug" type="slug" />" class="p-category">
<perch:category id="catTitle" type="text" suppress="true" />
</a>
</perch:categories>
And in post_category_list.html:
<perch:before>
<ul>
</perch:before>
<li><a href="/blog/category/<perch:category id="catSlug" />"><perch:category id="catTitle" /></a></li>
<perch:after>
</ul>
</perch:after>
I've also added the following patterns to my archive page:
blog/category/[slug:cat]
blog/tag/[slug:tag]
When I hover over the parent category, it links to blog/category/[parent] and the archive displays the posts in that category. All good.
When I hover over the sub-category, it links to blog/category/[sub-cat], but archive displays nothing.
This is the debug for the blank sub-cat archive:
Time Δ Debug Message
0.0812 0 SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
0.0823 0.0011 Matched route: blog/category/[slug:cat]
0.0824 0.0001 Using master page: /templates/pages/blog/archive.php
0.0824 0 Page arguments:
Array
(
[0] => /blog/category/exteriors
[cat] => exteriors
[1] => exteriors
)
0.0844 0.002 SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='0b639f8e7c89de87d9d4aa367cc169a9' LIMIT 1
0.0849 0.0005 UPDATE perch2_users SET userHash='818be44017dd764b75de6ce98f32cf0c' WHERE userID='1'
0.0852 0.0003 SELECT p.privKey FROM perch2_user_privileges p
0.0941 0.0089 SELECT * FROM perch2_pages WHERE pagePath='/blog/archive' LIMIT 1
0.0983 0.0042 SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
0.1052 0.007 SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1
0.1056 0.0003 SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catPath='exteriors/') ORDER BY catTreePosition ASC
0.1059 0.0003 Using template: /templates/categories/blog_cat_archive.html
0.1097 0.0038 Using template: /templates/mailchimp/subscribe.offcanvas.html
0.1152 0.0055 SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1
0.1168 0.0016 SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catPath='exteriors/') ORDER BY catTreePosition ASC
0.1173 0.0006 Using template: /templates/categories/blog_cat_archive.html
0.1178 0.0005 SELECT DISTINCT idx.itemID FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' AND (idx.indexKey='_category' AND idx.indexValue LIKE 'blog/exteriors/%' OR idx.indexKey='_category' AND idx.indexValue='blog/exteriors/')
0.1192 0.0015 SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='postDateTime' AND idx.itemID IN (NULL) WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2015-11-30 18:07:00' ) GROUP BY itemID ORDER BY sortval DESC LIMIT 0, 4
0.123 0.0037 SELECT FOUND_ROWS() AS `count`
0.1329 0.0099 Using template: /templates/blog/archive.html
0.1339 0.001 SELECT t.tagTitle, t.tagSlug, COUNT(p2t.postID) AS qty FROM perch2_blog_tags t, perch2_blog_posts_to_tags p2t, perch2_blog_posts p WHERE p2t.tagID=t.tagID AND p2t.postID=p.postID AND p.postStatus='Published' AND p.postDateTime<='2015-11-30 18:07:00' GROUP BY t.tagID ORDER BY t.tagTitle ASC
0.1358 0.0019 Using template: /templates/blog/tag_link.html
0.1476 0.0118 Using template: /templates/mailchimp/subscribe.html
0.1506 0.0031 Time: 0.1506
0.1507 0 Memory: 5.529
I've played around with changing catSlug to catPath in some places (template links as well as creating a ~~~blog/category/[slug:catPath]~~~ token (???), but a new problem arises...catPath turns URLs into: ~~~blog/category/blog/[parent]/[subcat]~~~ ...which is no good.
Are you guys able to shine any light on this? Thanks very much!
Using
catPath
is correct.Why is that no good? The matching route would be something like
Just because of that extra /blog in there between "category" and "[parent]" I'll give it another go and try that route.
Thanks Drew!
Use
replace="blog/|"
to get rid of it.I'm using the example archive.php file to filter my cats and subcats & having some issues
The cat title has stopped displaying all together.
The filtering will display posts at the parent cat level regardless of whether the parent or the subcat is selected.
I'm assuming it has to do with (perch_get('cat')) not looking at the subcat, any ideas Drew? Thank you !
perch_get('cat')
will get the category andperch_get('subcat')
will get the sub category.Success! Thank you Drew!!