<p>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.</p>

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

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

CC BY-SA 3.0
2018-03-18T08:58:46.523Z
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
CC BY-SA 3.0
2018-03-18T02:14:54.030Z
2018-03-18T02:14:54.030Z
mateostabio
<p>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".</p>

<p><a href="https://i.sstatic.net/QJV0Z.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QJV0Z.png" alt="What the main Nav has to look like"></a></p>

<p>I currently have this code that is displaying the total amount of entries</p>

<pre><code>{% set totalListings = craft.entries.section('listings').total() %}
{{ totalListings }}
</code></pre>

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

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

<conditional><navigation><forloop><entry-slug>
Dynamic Navigation with Condition to check slug
# Dynamic Navigation with Condition to check slug

(Asked by: username_0 on 2018-03-18)

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".

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') %}
 
    {% nav link in menu.all %}
        
           {{ link.title }}
        
    {% endnav %}

**Tags:** conditional, navigation, forloop, entry-slug

---

## 1 answers

### Answer by username_0 on 2018-03-18. Score: 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 %}
    
        {{ link.title }}{% if link.id == 15 %}{% set totalListings = craft.entries.section('listings').total() %}{{ totalListings }}{% endif %}
    
{% 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.

> **Comments:**
> **username_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`  

---

