Thread tagged as: Question, Blog

Perch if: more than one category

Hi, right now I have an h5 fed with post categories.

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


<perch:category id="catTitle" />

But they display all words together <h5>FootbalBasketball</h5> and I would like to make a conditional so it can go <h5>Football & Basketball</h5> and if there is only one category then go `<h5>Football</h5>``

Any ideas?

Raul Serrano

Raul Serrano 0 points

  • 4 years ago


I think you need to remove the <h5> tags from your page, and then do something like this in your template:

<perch:category id="catTitle" /><perch:if exists="!perch_item_last"> & </perch:if>

Not tested but I think this is pretty much right...

Hi Mike, it still gives <h5>Football Basket</h5> without &...

Hm maybe try


<perch:category id="catTitle" /><perch:if exists="perch_item_last"><perch:else/> & </perch:if>


Yeah! Thanks Mike!

No worries - looks like the not-exists doesn't work in categories

Duncan Revell

Duncan Revell 78 points
Registered Developer

Mike (and Raul)

<perch:if not-exists="perch_item_last"> & </perch:if>

Might work - Mike, you used !perch_item_last instead of not-exists... ;-)

Sounds good!

Haha thanks - I need some more sleep!