1

I'm trying to achieve one pretty simple thing, but putting it into my dynamic nav is making it a little difficult. I want to have a little number of the total amount of entries in my channel "listings" and keep it on one of the links "Our Properties".

What the main Nav has to look like

I currently have this code that is displaying the total amount of entries

{% set totalListings = craft.entries.section('listings').total() %}
{{ totalListings }}

How can I make this work: {% if link == "properties" single entry %} {{ totalListings}} {% endif %}

{% set menu = craft.entries.section('navigation') %}
<ul> 
    {% nav link in menu.all %}
        <li {% if craft.app.request.absoluteUrl == link.addentry[0].url %} class="active"{% endif %}>
           <a href="{{ link.addentry[0].url }}">{{ link.title }}</a>
        </li>
    {% endnav %}
</ul>
1

Got it to work! I don't know why I made it so complicated in my head, but I ended up using the link id to match with the properties link.

{% nav link in menu.all %}
    <li {% if craft.app.request.absoluteUrl == link.addentry[0].url %} class="active"{% endif %}>
        <a href="{{ link.addentry[0].url }}">{{ link.title }}{% if link.id == 15 %}<span class="exposant">{% set totalListings = craft.entries.section('listings').total() %}{{ totalListings }}</span>{% endif %}</a>
    </li>
{% endnav %}

If someone can show me how to get it by slug that would be awesome! Thanks & hope this will help someone in the future.

  • 1
    What do you mean with "get it by slug"? You can check the link.uri attribute for singles or the much better approach entry.getType.handle – Robin Schambach Mar 18 '18 at 8:58

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.