Forum
Multiple Category Sets in Blog
Hi Guys,
I want to use multiple category sets in the blog, but when I add this, I can no longer filter in the archive. I know it must be something I am doing wrong, but any direction/help you can offer? Here are my templates/code;
<p class="meta">
<perch:categories id="categories" set="news" label="Categories" display-as="checkboxes">
<a href="/news/category/<perch:category id="catSlug" type="slug" />" class="p-category">
<perch:category id="catTitle" type="text" />
</a>
</perch:categories>
<perch:categories id="categories_services" set="services" label="Services" display-as="checkboxes">
<a href="/news/category/<perch:category id="catSlug" type="slug" />" class="p-category">
<perch:category id="catTitle" type="text" />
</a>
</perch:categories>
</p>
<?php
if (!defined('PERCH_RUNWAY')) include($_SERVER['DOCUMENT_ROOT'].'/cms/runtime.php');
perch_layout('global/header', array(
'banner' => '',
));
perch_layout('global/breadcrumbs', array(
'type' => 'news'
));
?>
<div class="container">
<main role="main" class="content--primary">
<?php
// defaults for all modes
$posts_per_page = 5;
$template = 'post_in_list.html';
$sort_order = 'DESC';
$sort_by = 'postDateTime';
// Have we displayed any posts yet?
$posts_displayed = false;
/* --------------------------- POSTS BY CATEGORY --------------------------- */
if (perch_get('cat')) {
perch_blog_custom(array(
'category' => 'news/'.perch_get('cat'),
'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(array(
'template' => $template,
'count' => $posts_per_page,
'sort' => $sort_by,
'sort-order' => $sort_order,
));
}
?>
</main>
<?php
perch_layout('news/sidebar');
?>
</div>
<?php
perch_layout('global/footer');
?>
Is there a way to pass in multiple category sets rather then having to have unique ids and <perch:categories> for them in the template?
If you're not using the default
blog
set, then you need to make sure you specify a full category path to thecategory
option.It works ok for the practice news which is a category of news. Which in my first template is this;
But it won't work for any of the service categories, which in my template is this;
Neither use the default 'blog' set.
Drew. Sorry I have worked this out. I was being stupid. I had not filtered the services categories. Think this is resolved.