We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Problem, Blog

Multiple blogs Category filtering

I'm trying to get multiple blogs working on my site for the first time. The blogs will be 'blog' and 'resources'.

On my index pages I'm doing some filtering for that blog's posts using 'blog' => 'resources', which works fine in the perch_blog_custom array.

Passing the same thing into my categories works ok with the 'blog' blog but not with 'resources' blog…

This works fine:

perch_blog_categories([
  'sort' => 'catTitle',
  'sort-order' => 'ASC',
  'blog' => 'blog',
]);

But this doesn't return anything:

perch_blog_categories([
  'sort' => 'catTitle',
  'sort-order' => 'ASC',
  'blog' => 'resources',
]);

Do you know what I might be doing wrong?

Incidentally, it works fine with perch_blog_date_archive_years and perch_blog_tags.

This is my debug code:

Time    Δ   Debug Message
0.0693  0   [48] 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.071   0.0016  Matched page: /resources, so not using routes.
0.0711  0.0001  Using master page: /templates/pages/resources/index.php
0.0808  0.0097  [1] SELECT * FROM perch2_pages WHERE pagePath='/resources' LIMIT 1
0.0828  0.0021  Using template: /templates/pages/attributes/default.html
0.0837  0.0008  Using sub-template: /templates/pages/attributes/seo.html
0.0842  0.0005  Using sub-template: /templates/pages/attributes/open_graph.html
0.0846  0.0004  Using sub-template: /templates/pages/attributes/twitter.html
0.0977  0.0131  [5] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.0986  0.0009  [1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/resources' LIMIT 1
0.0989  0.0004  [1] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-006', '000') ORDER BY pageTreePosition DESC
0.0994  0.0005  [5] Using template: /templates/navigation/item.html
0.1053  0.0059  Using template: /templates/search/search-form.html
0.1186  0.0133  [3] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/resources' OR regionPage='*' ORDER BY regionPage DESC
0.1386  0.02    [1] SELECT blogID FROM perch2_blogs WHERE blogSlug='resources' LIMIT 1
0.1392  0.0006  [10] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='postDateTime' WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE ( blogID=1 AND postStatus='Published' AND postDateTime<='2016-04-26 16:18:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 10
0.1992  0.0601  [1] SELECT FOUND_ROWS() AS `count`
0.2047  0.0054  [63] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
0.2125  0.0078  [10] Using template: /templates/blog/post_in_list.html
0.2291  0.0166  Rescoping to perch:blog
0.2293  0.0002  Using sub-template: /templates/pagination/blog.html
0.2353  0.006   [1] SELECT * FROM perch2_blog_sections ORDER BY sectionTitle ASC
0.2371  0.0018  [2] SELECT * FROM perch2_blogs ORDER BY blogTitle ASC
0.2404  0.0033  [2] SELECT * FROM perch2_categories ORDER BY catTreePosition ASC
0.2582  0.0179  [1] SELECT * FROM perch2_blogs WHERE blogSlug='resources' LIMIT 1
0.2588  0.0006  [1] SELECT setID FROM perch2_category_sets WHERE setSlug='resources' LIMIT 1
0.2591  0.0003  [nil] SELECT main.* , COALESCE(cc.countValue,0) AS `count.blog.post` FROM perch2_categories main LEFT OUTER JOIN perch2_category_counts cc ON cc.catID=main.catID WHERE 1=1 AND setID=2 AND (cc.countType='blog.post' OR cc.countType IS NULL) AND cc.countValue > 0 ORDER BY catTitle ASC
0.2597  0.0006  Using template: /templates/blog/category_link.html
0.2602  0.0005  [1] SELECT * FROM perch2_blogs WHERE blogSlug='resources' LIMIT 1
0.2606  0.0004  [5] SELECT year(postDateTime) as year, COUNT(*) AS year_qty FROM perch2_blog_posts WHERE postStatus='Published' AND postDateTime<='2016-04-26 16:18:00' AND blogID=1 GROUP BY year ORDER BY year DESC
0.2615  0.0009  [5] Using template: /templates/blog/year_link.html
0.2645  0.003   [1] SELECT * FROM perch2_blogs WHERE blogSlug='resources' LIMIT 1
0.2649  0.0004  [42] SELECT t.tagTitle, t.tagSlug, COUNT(p2t.postID) AS qty FROM perch2_blog_tags t, perch2_blog_posts_to_tags p2t, perch2_blog_posts p WHERE p2t.tagID=t.tagID AND p2t.postID=p.postID AND p.postStatus='Published' AND p.postDateTime<='2016-04-26 16:18:00' AND p.blogID=1 GROUP BY t.tagID ORDER BY t.tagTitle ASC
0.268   0.0031  [42] Using template: /templates/blog/tag_link.html
0.2815  0.0135  [5] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.282   0.0005  [1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/resources' LIMIT 1
0.2822  0.0002  [1] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-006', '000') ORDER BY pageTreePosition DESC
0.2825  0.0003  [5] Using template: /templates/navigation/item.html
0.2856  0.0031  [1] SELECT groupID FROM perch2_navigation WHERE groupSlug='footer-nav' LIMIT 1
0.2859  0.0004  [4] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=2 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=2 ORDER BY np.pageTreePosition ASC
0.2865  0.0006  [0] SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=2 AND p.pagePath='/resources' LIMIT 1
0.287   0.0005  [4] Using template: /templates/navigation/list.html
0.2902  0.0032  [1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Primary content' AND (regionPage='/contact' OR regionPage='*')
0.2909  0.0007  [1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=324 AND idx.itemRev=62)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC
0.2937  0.0028  [1] Using template: /templates/content//footer_address.html
0.2962  0.0025  Request time: 0.2961
0.2963  0.0001  Process time: 0.2931
0.2963  0   Memory: 4.7362

and my diagnostics look like this:

Perch Runway: 2.8.29, PHP: 5.6.10, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.29), assets (2.8.29), categories (2.8.29), perch_blog (5.0), perch_forms (1.8.3), collection_1 (2.8.29), collection_2 (2.8.29), perch_backup (1.2)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_forms', );
PERCH_LOGINPATH: /cms
PERCH_PATH: /Users/TemperTemper/Sites/tempertemper/web/cms
PERCH_CORE: /Users/TemperTemper/Sites/tempertemper/web/cms/core
PERCH_RESFILEPATH: /Users/TemperTemper/Sites/tempertemper/web/cms/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: tempertemper.local
DOCUMENT_ROOT: /Users/TemperTemper/Sites/tempertemper/web
REQUEST_URI: /cms/core/settings/diagnostics/
SCRIPT_NAME: /cms/core/settings/diagnostics/index.php
Martin Underhill

Martin Underhill 5 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you go back to your posts in resources, are they showing their categories selected still?

There is an outstanding bug with categories in Blog.

Looks like the categories are outputting the same as before on the blog post page of the website. The corresponding entry in the control panel is using the 'blog' category set's checkboxes, which makes sense as I hadn't switched the set attribute on the post to anything different, so it must be using the cached data. (Truth be told, I hadn't got to the post, archive and rss pages yet – starting with the index) Switching the set on the post template to 'resources' and refreshing the control panel page brings up the right checkboxes though, with the right boxes checked.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'll want to turn off the caching, I think.

Do I do that in the config? I can't spot anything in the docs. Fingers crossed that fixes it :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

In the function options, add:

'cache' => false,

I've added it here:

perch_blog_categories([
  'blog'       => 'resources', // or 'blog' on the 'blog' blog :P
  'sort'       => 'catTitle',
  'sort-order' => 'ASC',
  'cache'      => false,
]);

But there's no difference when I refresh the page…

Drew McLellan

Drew McLellan 2638 points
Perch Support

Hmm, ok, I'll need to take a look and see what's going on.

Cool – thanks :)