Forum

Thread tagged as: Question, Problem, Blog

perch_blog_post_categories(perch_get('s') not working

Hi, just trying to finish of a blog by adding the current categories for the current blog post the user is reading by using the perch_blog_post_categories function but for some reason its not outputting anything.

im using a custom template so my php is:

<?php perch_blog_post_categories(perch_get('s'), array(
    'template' => 'post_category.html',
)); ?>

and in there is:

<perch:if exists="perch_item_last">
    <span>and</span> <a class="last" href="archive.php?cat=<perch:category id="catSlug" type="slug" for="catTitle" />">
         <perch:category id="catTitle" type="smarttext" label="Title" required="true" />
    </a>
<perch:else />
    <a class="last" href="archive.php?cat=<perch:category id="catSlug" type="slug" for="catTitle" />">
        <perch:category id="catTitle" type="smarttext" label="Title" required="true" />,
    </a>
</perch:if>

Also in my debug ive noticed that the bit where its talking about using the template above there is no number or anything on the right hand side, its blank, normally theres at least a number of some sorts in there. Also it says something about cache file not found. Ive tried different stuff out on my local build and a proper server and nothing, even just the perch_blog_post_categories function on its own returns nothing…

Debug:

Debug Message
[1] SELECT * FROM perch2_pages WHERE pagePath='/news-and-views/post.php' LIMIT 1
[5] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/news-and-views/post.php' OR regionPage='*' ORDER BY regionPage DESC
Using template: /templates/search/search-form.html
Using template: /templates/search/search-form.html
[1] 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='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='testing-blog-categories')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-09-12 10:43:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[23] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] Using template: /templates/blog/post.html
[2] SELECT * FROM perch2_blog_authors ORDER BY authorFamilyName, authorGivenName ASC
[1] SELECT * FROM perch2_blog_sections ORDER BY sectionTitle ASC
[1] SELECT * FROM perch2_blogs ORDER BY blogTitle ASC
[2] SELECT * FROM perch2_categories ORDER BY catTreePosition ASC
Fetching from cache: perch_blog_post_categories536e15e73a06e52908a0814965c2b201
Cache file not found: perch_blog_post_categories536e15e73a06e52908a0814965c2b201
[1] SELECT * FROM perch2_blog_posts WHERE postStatus='Published' AND postDateTime<='2016-09-12 10:43:00' AND postSlug='testing-blog-categories'
[] Using template: /templates/blog/post_category.html
[4] 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 ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-09-12 10:43:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 4
[1] SELECT FOUND_ROWS() AS `count`
[4] Using template: /templates/blog/post_in_side.html
[0] SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1
[6] SELECT main.* FROM perch2_categories main WHERE 1=1 ORDER BY catTreePosition ASC
[6] Using template: /templates/categories/category.html
[1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch2_pages WHERE pagePath='/private-clients' OR pageSortPath='/private-clients' LIMIT 1
[9] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageTreePosition LIKE '000-002%' ORDER BY pageTreePosition ASC
[0] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/news-and-views/post.php' LIMIT 1
[8] Using template: /templates/navigation/item.html
[1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch2_pages WHERE pagePath='/professional-partners' OR pageSortPath='/professional-partners' LIMIT 1
[3] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageTreePosition LIKE '000-004%' ORDER BY pageTreePosition ASC
[0] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/news-and-views/post.php' LIMIT 1
[2] Using template: /templates/navigation/item.html
[1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch2_pages WHERE pagePath='/corporate-clients' OR pageSortPath='/corporate-clients' LIMIT 1
[14] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageTreePosition LIKE '000-003%' ORDER BY pageTreePosition ASC
[0] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/news-and-views/post.php' LIMIT 1
[13] Using template: /templates/navigation/item.html
ewe agency

ewe agency 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like s on your URL is testing-blog-categories is that correct? Does that match the slug of the post you're trying to show categories for?

Yeah thats correct i just added a new blog to try get these post categories working

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does <perch:showall /> in your template give you?

It doesnt show anything, so that means that there are no categories set to be pulled in… But i have categories set up as im also using:

<?php perch_categories(); ?>

And this is the code im using to set the category for the blog post under post.html in perch:

        <perch:categories id="category" set="news-and-views" label="Category" suppress="true">
                    <perch:category id="catTitle" type="text" suppress="true" />
        </perch:categories>
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you don't use a custom template, does it output anything?

No still nothing

Drew McLellan

Drew McLellan 2638 points
Perch Support

Does it help if you re-save the blog post?

No ive tried that. Its strange i swear i had it working before but now it isnt but ive not changed anything with the blog

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you able to isolate the issue to a test page with nothing else on it?

Probably not without having to build another blog, but i can edit the template and take everything else out of it bar the blog post and the perch_blog_post_categories thats causing the problem

At a bit of a wall now, no clue why this isnt working. Ive tried re uploading the blog app files, creating a new category set and trying that.

I think its something to do with the actual perch_blog_post_categories function as even when i just put text in the template no perch stuff nothing gets pulled through

Drew McLellan

Drew McLellan 2638 points
Perch Support

Did you try the above as you were suggesting you would?

Yeah i took a back up and changed and simplified the post.php file but it didnt change anything

If <?php perch_categories(); ?> is working to pull the categories through but perch_blog_post_categories isnt am i adding the categories to the blog in the correct way?

ive tried this:

<perch:categories id="category" set="news-and-views" label="Category">
     <perch:category id="catTitle" type="text"  />
</perch:categories>

and this:

<perch:categories id="category" set="news-and-views" label="Category">

Just checked the database entry for the blog posts and under a post in the postDynamicFields row it is showing: "category":["2","4","5","6"]}. So the categories are getting captured just not being outputted by perch_blog_post_categories…

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, I'll need to take a look into it. I'm not sure I have an immediate solution.

Okay cheers, ill still keep having a go at trying stuff to see if it works in the mean time

A colleague of mine has fixed it. Its cos in the post.html template where i was setting the categories for the blog i was only pulling in the text for the category not a link for it so i needed to add this:

<perch:categories id="categories" set="news-and-views" label="Categories" suppress="true">
    <a href="archive.php?cat=<perch:category id="catSlug" type="slug" />">
        <perch:category id="catTitle" type="text" />
    </a>
</perch:categories>