Forum

Thread tagged as: Problem, Runway

perch_categories on any page

I'm trying to get perch_categories(); to work on a particular page. Actually I'm trying to get a particular set of categories:

perch_categories([
  'set'=>'platform',
]);

But it isn't finding anything. I tried a var_dump but it's returning NULL.

Is there a limitation as to which pages of a site I can call this function? I though it would've just output the categories wherever I asked it to, as it's not filtering any perch_content_custom or perch_collection content.

Thanks for keeping me right :)

Martin Underhill

Martin Underhill 5 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does debug output?

Time    Δ   Debug Message
0.0424  0   [28] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
0.0434  0.001   Matched page: /work/sector, so not using routes.
0.0435  0.0001  Using master page: /templates/pages/work/sector.php
0.044   0.0005  [1] SELECT collectionID, collectionTemplate FROM perch2_collections WHERE collectionKey='Work'
0.0443  0.0003  [nil] SELECT * FROM ( SELECT idx.itemID, ci.collectionID, ci.itemJSON, idx2.indexValue as sortval FROM perch2_collection_index idx JOIN perch2_collection_items ci ON idx.itemID=ci.itemID AND idx.itemRev=ci.itemRev AND idx.collectionID=ci.collectionID JOIN perch2_collection_revisions cr ON idx.itemID=cr.itemID AND idx.itemRev=cr.itemRev AND idx.collectionID=ci.collectionID JOIN perch2_collection_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE (idx.collectionID=1) AND ((idx.indexKey='slug' AND idx.indexValue='')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, itemJSON, sortval ORDER BY sortval ASC
0.047   0.0027  Using template: /templates/content/project.html
0.0472  0.0002  Using sub-template: /templates/content/blocks/one_image.html
0.0473  0.0001  Using sub-template: /templates/content/blocks/two_images.html
0.0474  0.0001  Using sub-template: /templates/content/text_block.html
0.0527  0.0054  [1] SELECT * FROM perch2_pages WHERE pagePath='/work/sector' LIMIT 1
0.0543  0.0015  Using template: /templates/pages/attributes/default.html
0.0544  0.0002  Using sub-template: /templates/pages/attributes/seo.html
0.0545  0.0001  Using sub-template: /templates/pages/attributes/open_graph.html
0.0546  0.0001  Using sub-template: /templates/pages/attributes/twitter.html
0.0547  0.0001  Using sub-template: /templates/pages/attributes/google_sitename.html
0.0616  0.007   [6] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=2 ORDER BY pageTreePosition ASC
0.0628  0.0012  [1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/work/sector' LIMIT 1
0.0632  0.0004  [2] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-002-002', '000-002', '000') ORDER BY pageTreePosition DESC
0.0639  0.0007  [6] Using template: /templates/navigation/item.html
0.0703  0.0065  [0] SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1
0.0708  0.0004  [nil] SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catPath='sector/') ORDER BY catTreePosition ASC
0.0711  0.0003  Using template: /templates/categories/category.html
0.0717  0.0006  [3] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/work/sector' OR regionPage='*' ORDER BY regionPage DESC
0.0732  0.0014  [1] SELECT setID FROM perch2_category_sets WHERE setSlug='sector' LIMIT 1
0.0747  0.0015  [5] SELECT main.* FROM perch2_categories main WHERE 1=1 AND setID=2 ORDER BY catTreePosition ASC
0.0764  0.0017  [5] Using template: /templates/categories/category.html
0.0805  0.0041  
Array
(
    [type] => 8
    [message] => Undefined offset: 0
    [file] => /Users/TemperTemper/Sites/Gospelware/gospelware.co.uk/web/cms/templates/layouts/sectors/header.php
    [line] => 21
)

and

Time    Δ   Debug Message
0.0424  0   [28] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
0.0434  0.001   Matched page: /work/sector, so not using routes.
0.0435  0.0001  Using master page: /templates/pages/work/sector.php
0.044   0.0005  [1] SELECT collectionID, collectionTemplate FROM perch2_collections WHERE collectionKey='Work'
0.0443  0.0003  [nil] SELECT * FROM ( SELECT idx.itemID, ci.collectionID, ci.itemJSON, idx2.indexValue as sortval FROM perch2_collection_index idx JOIN perch2_collection_items ci ON idx.itemID=ci.itemID AND idx.itemRev=ci.itemRev AND idx.collectionID=ci.collectionID JOIN perch2_collection_revisions cr ON idx.itemID=cr.itemID AND idx.itemRev=cr.itemRev AND idx.collectionID=ci.collectionID JOIN perch2_collection_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE (idx.collectionID=1) AND ((idx.indexKey='slug' AND idx.indexValue='')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, itemJSON, sortval ORDER BY sortval ASC
0.047   0.0027  Using template: /templates/content/project.html
0.0472  0.0002  Using sub-template: /templates/content/blocks/one_image.html
0.0473  0.0001  Using sub-template: /templates/content/blocks/two_images.html
0.0474  0.0001  Using sub-template: /templates/content/text_block.html
0.0527  0.0054  [1] SELECT * FROM perch2_pages WHERE pagePath='/work/sector' LIMIT 1
0.0543  0.0015  Using template: /templates/pages/attributes/default.html
0.0544  0.0002  Using sub-template: /templates/pages/attributes/seo.html
0.0545  0.0001  Using sub-template: /templates/pages/attributes/open_graph.html
0.0546  0.0001  Using sub-template: /templates/pages/attributes/twitter.html
0.0547  0.0001  Using sub-template: /templates/pages/attributes/google_sitename.html
0.0616  0.007   [6] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=2 ORDER BY pageTreePosition ASC
0.0628  0.0012  [1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/work/sector' LIMIT 1
0.0632  0.0004  [2] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-002-002', '000-002', '000') ORDER BY pageTreePosition DESC
0.0639  0.0007  [6] Using template: /templates/navigation/item.html
0.0703  0.0065  [0] SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1
0.0708  0.0004  [nil] SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catPath='sector/') ORDER BY catTreePosition ASC
0.0711  0.0003  Using template: /templates/categories/category.html
0.0717  0.0006  [3] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/work/sector' OR regionPage='*' ORDER BY regionPage DESC
0.0732  0.0014  [1] SELECT setID FROM perch2_category_sets WHERE setSlug='sector' LIMIT 1
0.0747  0.0015  [5] SELECT main.* FROM perch2_categories main WHERE 1=1 AND setID=2 ORDER BY catTreePosition ASC
0.0764  0.0017  [5] Using template: /templates/categories/category.html
0.0805  0.0041  
Array
(
    [type] => 8
    [message] => Undefined offset: 0
    [file] => /Users/TemperTemper/Sites/Gospelware/gospelware.co.uk/web/cms/templates/layouts/sectors/header.php
    [line] => 21
)
0.0819  0.0014  [6] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=2 ORDER BY pageTreePosition ASC
0.0857  0.0039  [1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/work/sector' LIMIT 1
0.0862  0.0005  [2] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-002-002', '000-002', '000') ORDER BY pageTreePosition DESC
0.0872  0.001   [6] Using template: /templates/navigation/item.html
0.093   0.0059  [25] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
0.0972  0.0041  Request time: 0.0971
0.0972  0.0001  Process time: 0.096
0.0972  0   Memory: 3.9409
0.0973  0.0001  
Array
(
    [type] => 8
    [message] => Undefined offset: 0
    [file] => /Users/TemperTemper/Sites/Gospelware/gospelware.co.uk/web/cms/templates/layouts/sectors/header.php
    [line] => 21
)

Nut sure why there are two, but they seem to be slightly different…

Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like you're getting 5 categories back for that set - does that sound about right?

That's right – the set contains 5 categories

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so it sounds like your template.

Have you tried <perch:showall /> ?

Great stuff! I've found the problem. Broken template :D Thanks for your help and sorry to have been such a numpty ;P