I have a custom list of breadcrumbs that two of the levels reference different Category Groups. I'm able to get the correct breadcrumb to display for the page that I'm on using category.title, but I need to display the correct category for the previous breadcrumb also.

I've made some progress and have managed to get it to display the first category in the group I want by using {% set county = craft.categories.group('counties').first() %} but I need it to display the category that I've attached to the page with a category field, and not just the first item in the category.

Here's the current code:

{% block breadcrumbs %}
    <div class="full-width breadcrumbs nav-breadcrumbs navbar-fixed-top">
        <div class='container'>
            <header class='scroll'>
                <span class='nav-item'><a href="/"><i class="icon-home"></i></a></span>
                <span class='nav-item'><a href="/developments">All Developments</a></span>
                {% set county = craft.categories.group('counties').first() %}
                <span class='nav-item'><a href="{{ county.url }}">{{ county.title }}</a></span>
                <span class='nav-item active'><a href="{{ category.url }}">{{ category.title }}</a></span>
{% endblock %}

I've managed to solve it. <span class='nav-item'><a href="{{ category.counties.first().url }}">{{ category.counties.first().title }}</a></span> did the trick.

Clearly I just needed to print the category field, although I'm not sure why it needs the .first() after category.counties to print it? But it works at least after days of struggling to find an answer.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.