Forum
Setting Categories in Template to Filter Custom Content
Hi all
Me again!
I'm currently putting together some 'department' pages. Within the content template, I'm using categories in order to set the department category to then filter other custom content on the page.
So for example, along the bottom of the page I am showing 4 blogs posts that are filtered by the category set in the content template. Like so:
perch_content('Content');
perch_blog_custom([
'sort' => 'postDateTime',
'sort-order' => DESC,
'count' => 4,
'template' => 'latest_posts.html',
'category' => 'departments/'.perch_get('cat'),
]);
and then in the template:
<perch:content id="content" type="textarea" label="Content" editor="redactor" html="true" />
<perch:categories id="catDept" set="departments" label="Department" help="Select which department this content relates to"></perch:categories>
...but nothing is showing.
Many thanks for your help as always.
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
Is
perch_get('cat')
being populated correctly?Hi Drew
perch:showall
is showing thecatDept
ID but not the category slug???Debug...
What's the value of
cat=
on your URL?Hi Drew
Sorry, this is the first proper site I'm building in Runway so still getting used to not having any static pages and using master pages with routes, collections and so on.
The URL is just the page path currently, so if I created a route
for-you/[slug:cat]
would that work? Although in this case both the page path and route would be the same:/for-you/residential-property
.It's easy to do statically but I am trying to do it dynamically so the client can add further pages for different departments using just the one 'department' master page.
Is creating a page for this the best method? The main content is only appearing on this one page with the latest blog posts that relate to that department at the bottom, along with a 'staff profile' collection in a side column to display images of all the staff that work in that department (again filtered using the category?).
Many thanks as always
Glen
perch_get('cat')
means "the value ofcat
from the URL". So for your code to work you need something on the URL to return that value.