Forum

Thread tagged as: Problem, Runway, Blog

Blog Categories Not Displaying On Archive Template

Sorry I know this has come up before I for some reason I can't get the blog categories to display using the archive.php template.

I'm using Runway (3.0.13) and have, I think, the routing set up correctly because if I view blog posts by year it works perfectly.

My routes look like

blog/[year:year]
blog/[year:year]/[i:month]
blog/category/[slug:cat]
blog/tag/[slug:tag]
blog/author/[slug:author]

So if I go to /blog/2017 it works, yet if I go to /blog/category/wga-news it only shows me a blank archive page.

So I'm guessing that it is routing to the archive page correctly but for some reason, the archive page itself isn't recognising the category slug?

Archive page:

<?php
    perch_layout('global/head', [
        'css' => '<link rel="stylesheet" href="/assets/css/blog.css">',
    ]);
    perch_layout('global/header');

    perch_pages_breadcrumbs();
?>

<div class="container">

<?php
    // defaults for all modes
    $posts_per_page = 16;
    $template       = 'blog/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>Archive of: '.perch_blog_category(perch_get('cat'), true).'</h1>';

        perch_blog_custom([
                'category'   => perch_get('cat'),
                'template'   => $template,
                'count'      => $posts_per_page,
                'sort'       => $sort_by,
                'sort-order' => $sort_order,
                ]);

        $posts_displayed = true;
    }


    /* --------------------------- POSTS BY TAG --------------------------- */
    if (perch_get('tag')) {
        echo '<h1>Archive of: '.perch_blog_tag(perch_get('tag'), true).'</h1>';

        perch_blog_custom([
                'tag'        => perch_get('tag'),
                'template'   => $template,
                'count'      => $posts_per_page,
                'sort'       => $sort_by,
                'sort-order' => $sort_order,
                ]);

        $posts_displayed = true;
    }



    /* --------------------------- POSTS BY DATE RANGE --------------------------- */
    if (perch_get('year')) {

        $year              = intval(perch_get('year'));
        $date_from         = $year.'-01-01 00:00:00';
        $date_to           = $year.'-12-31 23:59:59';
        $title_date_format = '%Y';


        // Month and Year?
        if (perch_get('month')) {
            $month             = intval(perch_get('month'));
            $date_from         = $year.'-'.str_pad($month, 2, '0', STR_PAD_LEFT).'-01 00:00:00';
            $date_to           = $year.'-'.str_pad($month, 2, '0', STR_PAD_LEFT).'-31 23:59:59';
            $title_date_format = '%B, %Y';
        }

        echo '<h1>Archive of: '.strftime($title_date_format, strtotime($date_from)).'</h1>';

        perch_blog_custom([
            'filter'     => 'postDateTime',
            'match'      => 'eqbetween',
            'value'      => $date_from.','.$date_to,
            'template'   => $template,
            'count'      => $posts_per_page,
            'sort'       => $sort_by,
            'sort-order' => $sort_order,
        ]);

        $posts_displayed = true;
    }



    /* --------------------------- POSTS BY AUTHOR --------------------------- */
    if (perch_get('author')) {

        echo '<h1>Posts by '.perch_blog_author(perch_get('author'), [
                                                'template' => 'author_name.html',
                                                ], true).'</h1>';


        perch_blog_custom([
                'author'     => perch_get('author'),
                'template'   => $template,
                'count'      => $posts_per_page,
                'sort'       => $sort_by,
                'sort-order' => $sort_order,
                ]);

        $posts_displayed = true;
    }


    /* --------------------------- DEFAULT: ALL POSTS --------------------------- */

    if ($posts_displayed == false) {

        // No other options have been used; no posts have been displayed yet.
        // So display all posts.

        echo '<h1>Archive</h1>';

        perch_blog_custom([
                'template'   => $template,
                'count'      => $posts_per_page,
                'sort'       => $sort_by,
                'sort-order' => $sort_order,
                ]);

    }

?>
</div>


<?php
    perch_content('Accreditations');
    perch_content('Phone Numbers Banner');

    perch_layout('global/az');
    perch_layout('global/footer');
    perch_layout('global/js');
    perch_layout('global/tracking');

Diagnostics:

Perch Runway: 3.0.13, PHP: 7.0.22, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (3.0.13), assets (3.0.13), categories (3.0.13), perch_blog (5.6.1), perch_forms (1.10), pipit_sharing (1.0.0)
App runtimes: <?php $apps_list = [ 'perch_forms', 'perch_blog', 'pipit_sharing' ];
PERCH_LOGINPATH: /perch
PERCH_PATH: /home/wga/CXPB7A7M/htdocs/perch
PERCH_CORE: /home/wga/CXPB7A7M/htdocs/perch/core
PERCH_RESFILEPATH: /home/wga/CXPB7A7M/htdocs/perch/resources
Image manipulation: GD Imagick
PHP limits: Max upload 128M, Max POST 128M, Memory: 256M, Total max file upload: 128M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
HTTP_HOST: wga.dns-systems.net
DOCUMENT_ROOT: /home/wga/CXPB7A7M/htdocs/
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Glen Piggott

Glen Piggott 0 points

  • 3 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

Give debug a go - it will tell you which route was matched and which values (if any) have been picked up from the url.

Thanks Duncan,

Debug doesn't seem to be showing any errors...

Time    Δ   Debug Message - Perch Runway 3.0.13
0.0641  0   [21] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate, pr.routeOrder, s.settingValue AS siteOffline FROM perch3_pages p LEFT JOIN perch3_page_routes pr ON p.pageID=pr.pageID LEFT JOIN perch3_settings s ON s.settingID='siteOffline' UNION SELECT NULL AS pagePath, pr2.routePattern, pr2.routeRegExp, pr2.templatePath AS pageTemplate, pr2.routeOrder, NULL AS siteOffline FROM perch3_page_routes pr2 WHERE templateID!=0 ORDER BY routeOrder ASC, pagePath ASC
0.0704  0.0063  Matched route: blog/category/[slug:cat]
0.0705  0.0001  Using master page: /templates/pages/blog/archive.php
0.0705  0   Page arguments:
Array
(
    [0] => /blog/category/conveyancing
    [cat] => conveyancing
    [1] => conveyancing
)
0.0712  0.0007  [38] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
0.0752  0.0039  [1] SELECT * FROM perch3_pages WHERE pagePath='/blog/archive' LIMIT 1
0.0879  0.0128  Using template: /templates/pages/attributes/default.html
0.0884  0.0004  Using sub-template: /templates/pages/attributes/seo.html
0.0897  0.0013  [7] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.09    0.0003  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/blog/archive' LIMIT 1
0.0905  0.0005  [2] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-007-003', '000-007', '000') ORDER BY pageTreePosition DESC
0.0909  0.0004  [7] Using template: /templates/navigation/top-navigation.html
0.0917  0.0008  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/blog/archive' OR pageSortPath='/blog/archive' LIMIT 1
0.092   0.0002  [1] SELECT * FROM perch3_pages WHERE pageHidden=0 AND pageNew=0 AND pageTreePosition IN ('000-007-003', '000-007', '000') ORDER BY pageTreePosition
0.0924  0.0004  [1] Using template: /templates/navigation/breadcrumbs.html
0.0937  0.0013  [1] SELECT * FROM perch3_categories WHERE catPath='blog/conveyancing/' LIMIT 1
0.0965  0.0029  [0] SELECT DISTINCT idx.itemID FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' AND ((idx.indexKey='_category' AND idx.indexValue LIKE 'blog/conveyancing/%' OR idx.indexKey='_category' AND idx.indexValue='blog/conveyancing/'))
0.1072  0.0106  [nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_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, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2018-01-12 11:04:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 16
0.1086  0.0014  [1] SELECT FOUND_ROWS() AS `count`
0.1262  0.0177  Using template: /templates/blog/archive.html
0.1366  0.0104  [2] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/blog/archive' OR regionPage='*' ORDER BY regionPage DESC
0.1379  0.0013  [7] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.1381  0.0002  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/blog/archive' LIMIT 1
0.1382  0.0001  [2] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-007-003', '000-007', '000') ORDER BY pageTreePosition DESC
0.1383  0.0001  [7] Using template: /templates/navigation/footer-navigation.html
Time    Δ   Debug Message - Perch Runway 3.0.13
0.0641  0   [21] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate, pr.routeOrder, s.settingValue AS siteOffline FROM perch3_pages p LEFT JOIN perch3_page_routes pr ON p.pageID=pr.pageID LEFT JOIN perch3_settings s ON s.settingID='siteOffline' UNION SELECT NULL AS pagePath, pr2.routePattern, pr2.routeRegExp, pr2.templatePath AS pageTemplate, pr2.routeOrder, NULL AS siteOffline FROM perch3_page_routes pr2 WHERE templateID!=0 ORDER BY routeOrder ASC, pagePath ASC
0.0704  0.0063  Matched route: blog/category/[slug:cat]
0.0705  0.0001  Using master page: /templates/pages/blog/archive.php
0.0705  0   Page arguments:
Array
(
    [0] => /blog/category/conveyancing
    [cat] => conveyancing
    [1] => conveyancing
)
0.0712  0.0007  [38] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
0.0752  0.0039  [1] SELECT * FROM perch3_pages WHERE pagePath='/blog/archive' LIMIT 1
0.0879  0.0128  Using template: /templates/pages/attributes/default.html
0.0884  0.0004  Using sub-template: /templates/pages/attributes/seo.html
0.0897  0.0013  [7] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.09    0.0003  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/blog/archive' LIMIT 1
0.0905  0.0005  [2] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-007-003', '000-007', '000') ORDER BY pageTreePosition DESC
0.0909  0.0004  [7] Using template: /templates/navigation/top-navigation.html
0.0917  0.0008  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/blog/archive' OR pageSortPath='/blog/archive' LIMIT 1
0.092   0.0002  [1] SELECT * FROM perch3_pages WHERE pageHidden=0 AND pageNew=0 AND pageTreePosition IN ('000-007-003', '000-007', '000') ORDER BY pageTreePosition
0.0924  0.0004  [1] Using template: /templates/navigation/breadcrumbs.html
0.0937  0.0013  [1] SELECT * FROM perch3_categories WHERE catPath='blog/conveyancing/' LIMIT 1
0.0965  0.0029  [0] SELECT DISTINCT idx.itemID FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' AND ((idx.indexKey='_category' AND idx.indexValue LIKE 'blog/conveyancing/%' OR idx.indexKey='_category' AND idx.indexValue='blog/conveyancing/'))
0.1072  0.0106  [nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_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, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2018-01-12 11:04:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 16
0.1086  0.0014  [1] SELECT FOUND_ROWS() AS `count`
0.1262  0.0177  Using template: /templates/blog/archive.html
0.1366  0.0104  [2] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/blog/archive' OR regionPage='*' ORDER BY regionPage DESC
0.1379  0.0013  [7] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.1381  0.0002  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/blog/archive' LIMIT 1
0.1382  0.0001  [2] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-007-003', '000-007', '000') ORDER BY pageTreePosition DESC
0.1383  0.0001  [7] Using template: /templates/navigation/footer-navigation.html
0.1395  0.0012  Request time: 0.1395
0.1395  0   Process time: 0.1388
0.1395  0   Memory: 3.4057

I think I can see the issue at: SELECT * FROM perch3_categories WHERE catPath='blog/conveyancing/' LIMIT 1.

The category path isn't blog/conveyancing it's department/conveyancing.

How do I get it to change the catPath from blog/ to department/

Duncan Revell

Duncan Revell 78 points
Registered Developer

Hi Glen,

I've never had this problem unfortunately - but I think others have on here. I guess try passing in the whole catPath (including department/) and see what happens. The blog functions do often assume a category set of blog...

Hi Duncan

I've managed to get it to work using...

perch_blog_custom([
            'category'   => array('departments/'.perch_get('cat'), 'offices/'.perch_get('cat')),
            'template'   => $template,
            'count'      => $posts_per_page,
            'sort'       => $sort_by,
            'sort-order' => $sort_order,

The only issue now is that I can't seem to echo the category title using perch_blog_category(perch_get('cat'), true) as it's not within the blog/ set.

I would also like to echo the catSlug but am having trouble with that too.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you're using Blog it presumes the blog category set unless you give it a full category path.