Forum

Thread tagged as: Question, Problem

Create breadcrumb using category path

Hi,

I have a Collection of real estate items, and each item is assigned a Location from a category set called Properties Location. This category set contains nested items and can be several levels deep.

When I show each item from the Collection, I also want to show a breadcrumb using the Location category path e.g. Location level 1 > Location level 2 > Location level 3.

I can get the full category path quite easily by using the following in my template:

<perch:categories id="property_location" set="property-location"><perch:category id="catPath" /></perch:categories>

And this returns /location-level-1/location-level-2/location-level-3/.

I'm wondering though if there an obvious Perch way to get this output as a breadcrumb? Or what would be the best approach to achieve this?

Thanks in advance for any pointers.

Simon Kelly

Simon Kelly 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you want to output the category title rather than the path?

Hi Drew,

Both, really. My aim is to get a breadcrumb list, with each item in the list showing the constituent parts of the path and a link for each. So if an item has a catPath of /location-level-1/location-level-2/location-level-3/ then I'm looking to get output of:

<ul>
<li><a href="/location-level-1/">Location level 1></a></li>
<li><a href="/location-level-2/">Location level 2></a></li>
<li><a href="/location-level-3/">Location level 3></a></li>
</ul>

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, how close to that have you got?

Well, I have the category path /location-level-1/location-level-2/location-level-3/ so I'm sure I could manipulate that string to create the markup above.

Ideally I'd like to achieve what I need by filtering using perch_categories() but I don't see how I can output the path parts as I need them from a category template. Is this possible?

I have this working on another site but I am away from the office today. I will look this code up tomorrow and post back.

Robert Ketter said:

I have this working on another site but I am away from the office today. I will look this code up tomorrow and post back.

Robert, that would be much appreciated, thanks.

I’ve been digging around. The code I found may not be what I thought. I’ll look some more,