Forum
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
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...
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'sdepartment/conveyancing
.How do I get it to change the catPath from
blog/
todepartment/
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 ofblog
...Hi Duncan
I've managed to get it to work using...
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 theblog/
set.I would also like to echo the
catSlug
but am having trouble with that too.If you're using Blog it presumes the
blog
category set unless you give it a full category path.