<p>You can use the <a href="https://craftcms.com/docs/templating/entrymodel#hasDescendants" rel="nofollow"><code>hasDescendants()</code></a> method to filter out any parent entry with children. You have to use an ElementCriteriaModel with <code>.getPrev()</code> and <code>.getNext()</code>.</p>

<pre><code>{% set entries = craft.entries.section( 'pages' ) %}
{% set entryIds = [] %}

{% for entry in entries %}
  {% if not entry.hasDescendants() %}
    {% set entryIds = entryIds|merge( [entry.id] ) %}
  {% endif %}
{% endfor %}

{% set criteria = craft.entries.id( entryIds ) %}

{% set prevEntry = entry.getPrev( criteria ) %}
{% set nextEntry = entry.getNext( criteria ) %}
</code></pre>

<p>You will also need to add logic to get the first and last entry is next or previous is null.</p>

CC BY-SA 3.0
2016-07-19T15:25:24.597Z
Hmm, that seems to make no difference at all. It still gives me the next entry as being a parent entry.
John
CC BY-SA 3.0
2016-07-19T15:43:41.077Z
Updated answer.
Luke Pearce
CC BY-SA 3.0
2016-07-19T15:51:30.450Z
Hmm, nope, now the prev next links don't show at all. No error though!
John
CC BY-SA 3.0
2016-07-19T15:52:24.437Z
Ah no, you had changed the section name to test and i didn't pick that up! Works a treat, thank you!!!!
John
CC BY-SA 3.0
2016-07-19T14:41:54.227Z
2016-07-19T15:55:40.420Z
2016-07-19T15:55:40.420Z
Luke Pearce
<p>I have a Structure with my entries in. How can I hide the parent entries that contain children? I still want to show the parents children.</p>

<p>For example I want all the below entries bar "About" and "Services"</p>

<pre><code>- Home
- About
    - Sub
    - Sub
    - Sub
- Stuff
- Services
    - Sub
    - Sub
    - Sub
- Things 
</code></pre>

<p>So, this is my code right now</p>

<pre><code>{# Set parameters for prev/next elements list #}
{% set params = craft.entries.section('pages') %}

{# Get the prev/next elements #}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
</code></pre>

<p>Do I need to modify the params to remove the entries that are parents?</p>

CC BY-SA 3.0
2016-07-19T14:26:12.083Z
Is this only being used to navigate between the previous and next entry?
Luke Pearce
<structure><pagination>
Only fetch structure entries that are first level or sub level that don't have a parent
# Only fetch structure entries that are first level or sub level that don't have a parent

(Asked by: username_0 on 2016-07-19)

I have a Structure with my entries in. How can I hide the parent entries that contain children? I still want to show the parents children.
For example I want all the below entries bar "About" and "Services"
- Home
- About
    - Sub
    - Sub
    - Sub
- Stuff
- Services
    - Sub
    - Sub
    - Sub
- Things 

So, this is my code right now
{# Set parameters for prev/next elements list #}
{% set params = craft.entries.section('pages') %}

{# Get the prev/next elements #}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}

Do I need to modify the params to remove the entries that are parents?

**Tags:** structure, pagination

> **Comments:**
> **username_1**: Is this only being used to navigate between the previous and next entry?  

---

## 1 answers

### Answer by username_1 on 2016-07-19. Score: 3 | Accepted answer

You can use the hasDescendants() method to filter out any parent entry with children. You have to use an ElementCriteriaModel with .getPrev() and .getNext().
{% set entries = craft.entries.section( 'pages' ) %}
{% set entryIds = [] %}

{% for entry in entries %}
  {% if not entry.hasDescendants() %}
    {% set entryIds = entryIds|merge( [entry.id] ) %}
  {% endif %}
{% endfor %}

{% set criteria = craft.entries.id( entryIds ) %}

{% set prevEntry = entry.getPrev( criteria ) %}
{% set nextEntry = entry.getNext( criteria ) %}

You will also need to add logic to get the first and last entry is next or previous is null.

> **Comments:**
> **username_0**: Hmm, that seems to make no difference at all. It still gives me the next entry as being a parent entry.  
> **username_1**: Updated answer.  
> **username_0**: Hmm, nope, now the prev next links don't show at all. No error though!  
> **username_0**: Ah no, you had changed the section name to test and i didn't pick that up! Works a treat, thank you!!!!  

---

