Forum

Thread tagged as: Question, Blog

Display the categories for each Blog Posts on the list page

Is there any way to list the categories for a Blog Post?

Specifically we want to pull into list page.

Have tried all the obvious ID's... but nothing seems to output anything expect <perch:blog id="categories" /> which just displays the number of categories for each post... eg: "=5" ?

Post template for categories:

perch:categories id="categories" set="blog" label="Categories" display-as="checkboxes" >
   <a href="service-detail.php?s=<perch:category id="catSlug" type="slug" />" class="p-category">
      <perch:category id="catTitle" type="text" />
   </a>
</perch:categories>

List template... have tried various ID's including:

<perch:blog id="category_names"/>
<perch:blog id="category_slugs"/>

But all output blank??

We need them to filter the list of posts using JS and a drop down. Is working great for location. Don't want to have to use tags, not as elegant to manage in CMS.

Thanks for any help on this.

Stuart Farrell

Stuart Farrell 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

<perch:categories id="categories" set="blog">
      <perch:category id="catTitle" type="text" />
</perch:categories>

Ah OK, so no simple Blog ID...... this works, but one issue.

When more than one category has been ticked for a post/item, they display without any space and two word categories display with a space. So you get "category onecategory two"

What we need is "category one, category two" or "category_one, category_two"

Should use use catSlug?

catSlug gives us "category-onecategory-two" - which is better, but how can we render with a comma?

If we add comma into template, it will appear for one category too... EG: <perch:categories id="categories" set="blog"><perch:category id="catSlug" />, </perch:categories>

Drew McLellan

Drew McLellan 2638 points
Perch Support

<perch:categories id="categories" set="blog">
      <perch:category id="catTitle" type="text" /><perch:if exists="perch_item_last"><perch:else />, </perch:if>
</perch:categories>

Dah, of course... it's 2:30am here, and that's my excuse. Used catSlug to avoid space issues.

Thanks.