<p>I assuming the pages are one level down from the parent?</p>

<pre><code>Parent
  | Child (1)
  | Child (2)
  | ... etc
</code></pre>

<p>You can do this:</p>

<pre><code>{% set topLevel =  entry.parent %}
{% set totalPages = topLevel.getDescendants().count() %}      
{% set entryIds = topLevel.getDescendants()|group('id')  %}
{% set currentPageNumber = (entryIds|keys)|indexOf(entry.id) + 1 %} 

{{currentPageNumber }} of {{totalPages}}
</code></pre>

<p>Basically we're making an array (list) out of just the entry IDs by grabbing the descendants from the parent. Then we use Craft's group function to give us an array, grouped by key (in this case the ID). Since we know the current page's ID, we can find it in the array and return its position. Since arrays are indexed starting with 0, we just add 1 to it.</p>

CC BY-SA 3.0
2015-11-05T18:00:25.263Z
Perfect! Thank you! The explanation was helpful
user1332211
CC BY-SA 3.0
2015-11-05T17:42:09.393Z
2015-11-05T17:42:09.393Z
RitterKnight
<p>You can get the position number within your branch with a <code>craft.entries</code> element criteria model and the following parameters set:</p>

<p><a href="http://buildwithcraft.com/docs/templating/craft.entries#id" rel="nofollow"><code>id</code></a> – to search only in the current branch, pass the current entry's siblings IDs<br>
<a href="http://buildwithcraft.com/docs/templating/craft.entries#positionedBefore" rel="nofollow"><code>positionedBefore</code></a> – set this param to get entries positioned before the current entry</p>

<pre><code>{% set parent = entry.getParent() %}
{% set siblingsIds = parent.getChildren().ids() %}
{% set total = siblingsIds|length %}

{% set positionedBefore = craft.entries.id(siblingsIds).positionedBefore(entry).order('lft desc') %}
{% set position = positionedBefore.total() + 1 %}

{{ position }} / {{ total }}
</code></pre>

CC BY-SA 3.0
2015-11-05T17:59:16.267Z
2015-11-05T17:59:16.267Z
carlcs
<p>I have a Structure section with an ordered number of entries under a parent. On each entry I would like to add a status message of the user's current progress... i.e. <code>You are on page 1 of 5 pages.</code></p>

<p>The total was easy... </p>

<pre><code>{% set total = entry.getParent(entry).getDescendants().count() %}
</code></pre>

<p>How do I get the current page (child) number within the total number of children.</p>

<p>Thanks!</p>

<structure>
How can I create a status message of X of TOTAL pages under a parent?
# How can I create a status message of X of TOTAL pages under a parent?

(Asked by: username_0 on 2015-11-05)

I have a Structure section with an ordered number of entries under a parent. On each entry I would like to add a status message of the user's current progress... i.e. You are on page 1 of 5 pages.
The total was easy... 
{% set total = entry.getParent(entry).getDescendants().count() %}

How do I get the current page (child) number within the total number of children.
Thanks!

**Tags:** structure

---

## 2 answers

### Answer by username_1 on 2015-11-05. Score: 1 | Accepted answer

I assuming the pages are one level down from the parent?
Parent
  | Child (1)
  | Child (2)
  | ... etc

You can do this:
{% set topLevel =  entry.parent %}
{% set totalPages = topLevel.getDescendants().count() %}      
{% set entryIds = topLevel.getDescendants()|group('id')  %}
{% set currentPageNumber = (entryIds|keys)|indexOf(entry.id) + 1 %} 

{{currentPageNumber }} of {{totalPages}}

Basically we're making an array (list) out of just the entry IDs by grabbing the descendants from the parent. Then we use Craft's group function to give us an array, grouped by key (in this case the ID). Since we know the current page's ID, we can find it in the array and return its position. Since arrays are indexed starting with 0, we just add 1 to it.

> **Comments:**
> **username_0**: Perfect! Thank you! The explanation was helpful  

---

### Answer by username_2 on 2015-11-05. Score: 1

You can get the position number within your branch with a craft.entries element criteria model and the following parameters set:
id – to search only in the current branch, pass the current entry's siblings IDs
positionedBefore – set this param to get entries positioned before the current entry
{% set parent = entry.getParent() %}
{% set siblingsIds = parent.getChildren().ids() %}
{% set total = siblingsIds|length %}

{% set positionedBefore = craft.entries.id(siblingsIds).positionedBefore(entry).order('lft desc') %}
{% set position = positionedBefore.total() + 1 %}

{{ position }} / {{ total }}


---

