Forum

Thread tagged as: Problem, Runway, Blog

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!

Olympia Kyriakides

Olympia Kyriakides 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Using catPath is correct.

URLs into: blog/category/blog/[parent]/[subcat] ...which is no good.

Why is that no good? The matching route would be something like

blog/category/[slug:cat]/[slug:subcat]

Just because of that extra /blog in there between "category" and "[parent]" I'll give it another go and try that route.

Thanks Drew!

Drew McLellan

Drew McLellan 2638 points
Perch Support

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


<?php // defaults for all modes $posts_per_page = 4; $template = 'archive.html'; $sort_order = 'DESC'; $sort_by = 'postDateTime'; // Have we displayed any posts yet? $posts_displayed = false; /* perch_get() is used to get options from the URL. e.g. for the URL /blog/archive.php?cat=news perch_get('cat') would return 'news' because cat=news. The code below looks for different options in the URL, and then displays different types of listings based on it. */ /* --------------------------- POSTS BY CATEGORY --------------------------- */ if (perch_get('cat')) { echo '<h1 class="post-section-header">'.perch_category(perch_get('cat'), array ('template'=>'blog_cat_archive.html',),true).'</h1>'; perch_blog_custom(array( 'category' => perch_get('cat'), 'template' => $template, 'count' => $posts_per_page, 'sort' => $sort_by, 'sort-order' => $sort_order, )); $posts_displayed = true; } ?> TEMPLATE blog_cat_archive.html <perch:category id="catTitle" type="smarttext" label="Title" required="true"/> <perch:category id="catPath" type="slug" for="catTitle" suppress="true" /> <perch:category id="desc" type="textarea" label="Description" editor="markitup" markdown="true" size="s" /> TO DISPLAY THE CAT TITLE: <?php if (perch_get('cat')) {echo perch_category(perch_get('cat'), array ('template'=>'blog_cat_archive.html',),true); $posts_displayed = true;} ?>

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 !

0.0841  0.0023  Matched route: blog/category/[slug:cat]/[slug:subcat]
0.0842  0.0001  Using master page: /templates/pages/blog/archive.php
0.0842  0   Page arguments:
Array
(
    [0] => /blog/category/design/interiors
    [cat] => design
    [1] => design
    [subcat] => interiors
    [2] => interiors
)

0.1195  0.0071  SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1
0.1236  0.0041  SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catPath='design/') ORDER BY catTreePosition ASC
0.1251  0.0014  Using template: /templates/categories/blog_cat_archive.html
0.1256  0.0006  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/design/%' OR idx.indexKey='_category' AND idx.indexValue='blog/design/')
Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_get('cat') will get the category and perch_get('subcat') will get the sub category.

'category' => 'blog/'.perch_get('cat').'/'.perch_get('subcat'),

Success! Thank you Drew!!