Forum

Thread tagged as: Question, Runway, Blog

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
Glen Piggott

Glen Piggott 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is perch_get('cat') being populated correctly?

Hi Drew

perch:showall is showing the catDept ID but not the category slug???

perch_page_path /perch/core/apps/content/edit/index.php
_id 45
content 
Property purchase is a major investment, and moving home is generally ranked as one of the most stressful events in people's lives. Our aim is to ensure that all the legal aspects of your purchase and/or sale go as smoothly as possible, leaving you free to deal with the practical side of the move. We offer a range of services tailored to a variety of different clients; from those buying their first home to repeat purchases building property portfolios. We advise both Landlords and Tenants and offer guidance to those facing boundary or planning issues.

More Information on Ward Gethin Archer's Residential Property lawyers services can be found by clicking on the links below:

Residential Property
Buying Property
Selling Property
Remortgage
Lettings
Equity Release
To obtain a conveyancing quote from a member of our property team please click here to contact us.

At present the Home Information Pack required to sell a property has been suspended. The only requirement now is for an Energy Performance Certificate. We are more than happy to arrange this for you and the cost is around £50.

catDept 
Array
(
    [0] => 2
)
itemRowID   1613
itemID  45
regionID    50
pageID  22
itemRev 10
itemOrder   1000
itemJSON    {"_id":"45","content":{"_flang":"html","raw":"Property purchase is a major investment, and moving{...}
itemSearch  Property purchase is a major investment, and moving home is generally ranked as one of the most{...}
itemUpdated 2018-01-24 16:57:43
itemUpdatedBy   1
perch_item_first    true
perch_item_last true
perch_item_zero_index   0
perch_item_index    1
perch_item_rev_index    1
perch_item_rev_zero_index   0
perch_item_odd  
perch_item_count    1
perch_namespace perch:content

Debug...

Time    Δ   Debug Message - Perch Runway 3.0.13
0.0326  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.0352  0.0026  Matched page: /for-you/residential-property, so not using routes.
0.0353  0.0001  Using master page: /templates/pages/departments.php
0.0359  0.0006  [38] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
0.0409  0.0049  [1] SELECT * FROM perch3_pages WHERE pagePath='/for-you/residential-property' LIMIT 1
0.0421  0.0013  Using template: /templates/pages/attributes/default.html
0.0425  0.0004  Using sub-template: /templates/pages/attributes/seo.html
0.0438  0.0013  [6] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.044   0.0002  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/for-you/residential-property' LIMIT 1
0.0441  0.0001  [2] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-002-001', '000-002', '000') ORDER BY pageTreePosition DESC
0.0442  0.0002  [6] Using template: /templates/navigation/top-navigation.html
0.0449  0.0006  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/for-you/residential-property' OR pageSortPath='/for-you/residential-property' LIMIT 1
0.045   0.0001  [2] SELECT * FROM perch3_pages WHERE pageHidden=0 AND pageNew=0 AND pageTreePosition IN ('000-002-001', '000-002', '000') ORDER BY pageTreePosition
0.0451  0.0001  [2] Using template: /templates/navigation/breadcrumbs.html
0.0455  0.0004  [5] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/for-you/residential-property' OR regionPage='*' ORDER BY regionPage DESC
0.0459  0.0004  [1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch3_pages WHERE pagePath='/for-you/residential-property' OR pageSortPath='/for-you/residential-property' LIMIT 1
0.046   0.0001  [1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch3_pages WHERE pageTreePosition='000-002' LIMIT 1
0.0461  0.0001  [3] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageTreePosition LIKE '000-002%' ORDER BY pageTreePosition ASC
0.0462  0.0001  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/for-you/residential-property' LIMIT 1
0.0463  0.0001  [2] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-002-001', '000-002', '000') ORDER BY pageTreePosition DESC
0.0464  0.0001  Using template: /templates/navigation/departments_subnav_header.html
0.0465  0.0001  [1] Using template: /templates/navigation/departments_subnav.html
0.0495  0.003   [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/departments/%' OR idx.indexKey='_category' AND idx.indexValue='blog/departments/'))
0.0499  0.0004  [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-24 16:59:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 4
0.0512  0.0013  [1] SELECT FOUND_ROWS() AS `count`
0.0523  0.0011  Using template: /templates/blog/latest_posts.html
0.053   0.0008  [6] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.0532  0.0002  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/for-you/residential-property' LIMIT 1
0.0533  0.0001  [2] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-002-001', '000-002', '000') ORDER BY pageTreePosition DESC
0.0534  0.0001  [6] Using template: /templates/navigation/footer-navigation.html
0.0542  0.0008  
Array
(
    [type] => 8
    [message] => Use of undefined constant DESC - assumed 'DESC'
    [file] => /home/wga/CXPB7A7M/htdocs/perch/templates/pages/departments.php
    [line] => 58
)
Time    Δ   Debug Message - Perch Runway 3.0.13
0.0326  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.0352  0.0026  Matched page: /for-you/residential-property, so not using routes.
0.0353  0.0001  Using master page: /templates/pages/departments.php
0.0359  0.0006  [38] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
0.0409  0.0049  [1] SELECT * FROM perch3_pages WHERE pagePath='/for-you/residential-property' LIMIT 1
0.0421  0.0013  Using template: /templates/pages/attributes/default.html
0.0425  0.0004  Using sub-template: /templates/pages/attributes/seo.html
0.0438  0.0013  [6] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.044   0.0002  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/for-you/residential-property' LIMIT 1
0.0441  0.0001  [2] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-002-001', '000-002', '000') ORDER BY pageTreePosition DESC
0.0442  0.0002  [6] Using template: /templates/navigation/top-navigation.html
0.0449  0.0006  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/for-you/residential-property' OR pageSortPath='/for-you/residential-property' LIMIT 1
0.045   0.0001  [2] SELECT * FROM perch3_pages WHERE pageHidden=0 AND pageNew=0 AND pageTreePosition IN ('000-002-001', '000-002', '000') ORDER BY pageTreePosition
0.0451  0.0001  [2] Using template: /templates/navigation/breadcrumbs.html
0.0455  0.0004  [5] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/for-you/residential-property' OR regionPage='*' ORDER BY regionPage DESC
0.0459  0.0004  [1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch3_pages WHERE pagePath='/for-you/residential-property' OR pageSortPath='/for-you/residential-property' LIMIT 1
0.046   0.0001  [1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch3_pages WHERE pageTreePosition='000-002' LIMIT 1
0.0461  0.0001  [3] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageTreePosition LIKE '000-002%' ORDER BY pageTreePosition ASC
0.0462  0.0001  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/for-you/residential-property' LIMIT 1
0.0463  0.0001  [2] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-002-001', '000-002', '000') ORDER BY pageTreePosition DESC
0.0464  0.0001  Using template: /templates/navigation/departments_subnav_header.html
0.0465  0.0001  [1] Using template: /templates/navigation/departments_subnav.html
0.0495  0.003   [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/departments/%' OR idx.indexKey='_category' AND idx.indexValue='blog/departments/'))
0.0499  0.0004  [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-24 16:59:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 4
0.0512  0.0013  [1] SELECT FOUND_ROWS() AS `count`
0.0523  0.0011  Using template: /templates/blog/latest_posts.html
0.053   0.0008  [6] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.0532  0.0002  [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/for-you/residential-property' LIMIT 1
0.0533  0.0001  [2] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-002-001', '000-002', '000') ORDER BY pageTreePosition DESC
0.0534  0.0001  [6] Using template: /templates/navigation/footer-navigation.html
0.0542  0.0008  
Array
(
    [type] => 8
    [message] => Use of undefined constant DESC - assumed 'DESC'
    [file] => /home/wga/CXPB7A7M/htdocs/perch/templates/pages/departments.php
    [line] => 58
)
0.0545  0.0003  Request time: 0.0545
0.0545  0   Process time: 0.0537
0.0545  0   Memory: 3.3221
0.0545  0   
Array
(
    [type] => 8
    [message] => Use of undefined constant DESC - assumed 'DESC'
    [file] => /home/wga/CXPB7A7M/htdocs/perch/templates/pages/departments.php
    [line] => 58
)
Drew McLellan

Drew McLellan 2638 points
Perch Support

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

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_get('cat') means "the value of cat from the URL". So for your code to work you need something on the URL to return that value.