Forum

Thread tagged as: Question, Addons, Blog

Display only parent category for blog post / hide sub-categories

I'd like to display only the parent category (via post_in_list.html) for each post on my main blog index page. I still want to apply sub-categories and have them available within the actual posts and for archiving purposes.

This is what I have now and it displays both parent and sub-categories on my blog index page:

<perch:categories id="categories" set="blog"> <a href="archive.php?cat=<perch:category id="catSlug" type="slug" />" class="p-category"> <perch:category id="catTitle" type="text" /> </a> </perch:categories>

Any help would be greatly appreciated! Thank you!

Olympia Kyriakides

Olympia Kyriakides 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You could test for catParentID being 0:

<perch:categories id="categories" set="blog">
    <perch:if id="catParentID" value="0">
        ... display your category ...
    </perch:if>
</perch:categories>

Perfect! Thank you Drew!!