<p>Use a <a href="http://buildwithcraft.com/docs/templating/craft.entries#descendantOf" rel="nofollow"><code>descendantOf</code></a> parameter with a new ElementCriteriaModel instead of the <a href="http://buildwithcraft.com/docs/templating/entrymodel#getDescendants" rel="nofollow"><code>getDescendants</code></a> method on your entry model and you can add additional parameters. In your case add <code>cf_hideFromNav</code> as a parameter:</p>

<pre><code>{% set topEntry = craft.entries.section('pages').slug('club').first() %}
{% set navItems = craft.entries.section('pages').descendantOf(topEntry).cf_hideFromNav('0') %}

{% nav navItem in navItems %}
    ...
{% endnav %}
</code></pre>

<p>You could also use the parameters <a href="http://buildwithcraft.com/docs/templating/craft.entries#id" rel="nofollow"><code>id</code></a> or <a href="http://buildwithcraft.com/docs/templating/craft.entries#slug" rel="nofollow"><code>slug</code></a> to exclude certain entries:</p>

<pre><code>{% set topEntry = craft.entries.section('pages').slug('club').first() %}
{% set navItems = craft.entries.section('pages').descendantOf(topEntry).id('and, not 23, not 40, not 12') %}
</code></pre>

<p>The <a href="http://buildwithcraft.com/docs/templating/craft.entries#descendantOf" rel="nofollow"><code>descendantOf</code></a> parameter also takes IDs. This would allow you to do this all with just a single ElementCriteriaModel:</p>

<pre><code>{% set navItems = craft.entries.section('pages').descendantOf('1').id('and, not 23, not 40, not 12') %}
</code></pre>

CC BY-SA 3.0
2014-08-27T14:50:50.273Z
hi, that was exactly what I was after! but to my surprise it's not working!
outline4
CC BY-SA 3.0
2014-08-27T14:51:38.357Z
this works: {% set navItems = craft.entries.section('pages').descendantOf(topEntry).cf_hideFromNav('1') %} -> it only shows the navItems that should not be displayed... but the other way round it doesn't work... bug?
outline4
CC BY-SA 3.0
2014-08-27T14:52:29.217Z
but this works: {% set navItems = craft.entries.section('pages').descendantOf(topEntry).cf_hideFromNav('not 1') %} -> strange!
outline4
CC BY-SA 3.0
2014-08-27T15:05:58.837Z
Nice you got it working, @outline4! Lightswitches write `0` to the DB if not active, so it's in fact strange!
carlcs
CC BY-SA 3.0
2014-08-27T13:27:01.963Z
2014-08-27T13:48:31.577Z
2014-08-27T13:48:31.577Z
carlcs
<p>I am looking for a way to exclude certain pages from the navigation. I know it must be quite easy, but nothing seems to work for me at the moment. </p>

<p>So I've setup a lightswitch field "exclude from navigation" (cf_hideFromNav)</p>

<p>Problem is that I want the navigation to start only from a certain slug: </p>

<pre><code>{% set topEntry = craft.entries.section('pages').depth(1).slug('club').first() %}
{% set descendants = topEntry.getDescendants()  %}              
&lt;ul&gt;
    {% nav entry in descendants %}
        &lt;li&gt;
            {{ entry.title }} 
            {% ifchildren %}&lt;ul&gt;{% children %}&lt;/ul&gt;{% endifchildren %}
        &lt;/li&gt;
    {% endnav %}
&lt;/ul&gt;
</code></pre>

<p>how could I incorporate the cf_hideFromNav in this equation?</p>

<p>any help appreciated!<br>
cheers<br>
stefan</p>

<navigation>
How to exclude a page from the navigation tree
# How to exclude a page from the navigation tree

(Asked by: username_0 on 2014-08-27)

I am looking for a way to exclude certain pages from the navigation. I know it must be quite easy, but nothing seems to work for me at the moment. 
So I've setup a lightswitch field "exclude from navigation" (cf_hideFromNav)
Problem is that I want the navigation to start only from a certain slug: 
{% set topEntry = craft.entries.section('pages').depth(1).slug('club').first() %}
{% set descendants = topEntry.getDescendants()  %}              

    {% nav entry in descendants %}
        
            {{ entry.title }} 
            {% ifchildren %}{% children %}{% endifchildren %}
        
    {% endnav %}


how could I incorporate the cf_hideFromNav in this equation?
any help appreciated!
cheers
stefan

**Tags:** navigation


---

## 1 answers

### Answer by username_1 on 2014-08-27. Score: 2 | Accepted answer

Use a descendantOf parameter with a new ElementCriteriaModel instead of the getDescendants method on your entry model and you can add additional parameters. In your case add cf_hideFromNav as a parameter:
{% set topEntry = craft.entries.section('pages').slug('club').first() %}
{% set navItems = craft.entries.section('pages').descendantOf(topEntry).cf_hideFromNav('0') %}

{% nav navItem in navItems %}
    ...
{% endnav %}

You could also use the parameters id or slug to exclude certain entries:
{% set topEntry = craft.entries.section('pages').slug('club').first() %}
{% set navItems = craft.entries.section('pages').descendantOf(topEntry).id('and, not 23, not 40, not 12') %}

The descendantOf parameter also takes IDs. This would allow you to do this all with just a single ElementCriteriaModel:
{% set navItems = craft.entries.section('pages').descendantOf('1').id('and, not 23, not 40, not 12') %}

> **Comments:**
> **username_0**: hi, that was exactly what I was after! but to my surprise it's not working!  
> **username_0**: this works: {% set navItems = craft.entries.section('pages').descendantOf(topEntry).cf_hideFromNav('1') %} -> it only shows the navItems that should not be displayed... but the other way round it doesn't work... bug?  
> **username_0**: but this works: {% set navItems = craft.entries.section('pages').descendantOf(topEntry).cf_hideFromNav('not 1') %} -> strange!  
> **username_1**: Nice you got it working, @username_0! Lightswitches write `0` to the DB if not active, so it's in fact strange!  

---

