Forum
Perch Categories (related posts) query
Trying to get a list of posts related to the currently shown post. This is done by categories and must factor in multiple categories if present.
category_only.html:
<perch:category id="catSlug" type="slug" for="catTitle" /><perch:if exists="perch_item_last"><perch:else />|</perch:if>
post.php
<?php
$cats = perch_blog_post_categories(perch_get('s'), array(
'template'=>'category_only.html',
), true);
$cats = explode('|',$cats);
perch_blog_custom(array(
'category' => $cats,
));
?>
With above, can get $cats
to contain an array of relevant category handles.
However when passed into the perch_blog_custom()
function this returns empty.
Any thoughts?
If you
print_r($cats)
does it look like you'd expect?Yep:
That looks like it should work. Are you categories in a set called
blog
?No, they're in a set called 'perspectives'. However, even if I update the page function no results are returned:
Does
perch_blog_custom
support custom sets?Blog expects things to use its category set unless you tell it otherwise. The
category
option takes category paths so use those.Change:
to
Brilliant thanks, hadn't appreciated the sets prefix.