# Select first number of subpages

**URL:** <https://forum.getkirby.com/t/select-first-number-of-subpages/16738>\
**Category:** Questions\
**Tags:** v3\
**Created:** [December 26, 2019, 1:49pm UTC](https://forum.getkirby.com/t/select-first-number-of-subpages/16738 "2019-12-26T13:49:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vandelay](https://avatars.discourse-cdn.com/v4/letter/v/278dde/32.png) [@vandelay](https://forum.getkirby.com/u/vandelay)\
**Post date:** [December 26, 2019, 1:49pm UTC](https://forum.getkirby.com/t/select-first-number-of-subpages/16738/1 "2019-12-26T13:49:41Z")

</div>

Hi, is there a way to select a few subpages by their position? For example, select first 5 pages or select pages 6 onwards?

Here’s the what I am trying to do. Thanks.

```
<ul class="top_block">
<?php
$topItems = $data->children()->listed(); //select only the first 5 pages
foreach ($topItems as $topItem): ?> 

	<li class="items_one_to_five">
		<a href="<?= $topItem->link() ?>">
		</a>
	</li>

<?php endforeach ?>
</ul>

<ul class="bottom_block">
<?php
$items = $data->children()->listed(); //select all the rest
foreach ($items as $item): ?> 

	<li class="items_six_on">
		<a href="<?= $item->link() ?>">
		</a>
	</li>

<?php endforeach ?>
</ul>

```

---

<div class="post-metadata">

**Author:** ![ahmetbora](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahmetbora/32/11671_2.png) [@ahmetbora](https://forum.getkirby.com/u/ahmetbora)\
**Post date:** [December 26, 2019, 2:00pm UTC](https://forum.getkirby.com/t/select-first-number-of-subpages/16738/2 "2019-12-26T14:00:26Z")

</div>

You can use [limit()](https://getkirby.com/docs/reference/objects/pages/limit) and [offset()](https://getkirby.com/docs/reference/objects/pages/offset) methods:

```
$data->children()->listed()->limit(5); // Get top 5 items

$data->children()->listed()->offset(5); // Get items after 5 offset
```

---

<div class="post-metadata">

**Author:** ![vandelay](https://avatars.discourse-cdn.com/v4/letter/v/278dde/32.png) [@vandelay](https://forum.getkirby.com/u/vandelay)\
**Post date:** [December 26, 2019, 2:03pm UTC](https://forum.getkirby.com/t/select-first-number-of-subpages/16738/3 "2019-12-26T14:03:19Z")

</div>

> [@ahmetbora](#):
>
> $data-\>children()-\>listed()-\>nth(5);

Thanks!  
offset() works great! but nth(5) returns an error. Any idea why?

---

<div class="post-metadata">

**Author:** ![ahmetbora](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahmetbora/32/11671_2.png) [@ahmetbora](https://forum.getkirby.com/u/ahmetbora)\
**Post date:** [December 26, 2019, 2:05pm UTC](https://forum.getkirby.com/t/select-first-number-of-subpages/16738/5 "2019-12-26T14:05:09Z")

</div>

Ahh sorry, you need use [limit()](https://getkirby.com/docs/reference/objects/pages/limit) method like that:

```
$data->children()->listed()->limit(5); // Get top 5 items
```

---

<div class="post-metadata">

**Author:** ![vandelay](https://avatars.discourse-cdn.com/v4/letter/v/278dde/32.png) [@vandelay](https://forum.getkirby.com/u/vandelay)\
**Post date:** [December 26, 2019, 2:07pm UTC](https://forum.getkirby.com/t/select-first-number-of-subpages/16738/6 "2019-12-26T14:07:30Z")

</div>

That works perfect! Thanks!

---

<div class="post-metadata">

**Author:** ![ahmetbora](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahmetbora/32/11671_2.png) [@ahmetbora](https://forum.getkirby.com/u/ahmetbora)\
**Post date:** [December 26, 2019, 2:08pm UTC](https://forum.getkirby.com/t/select-first-number-of-subpages/16738/7 "2019-12-26T14:08:46Z")

</div>

You can look out other incredible `$pages` collection methods from here:

> **[$pages](https://getkirby.com/docs/reference/objects/pages)**
>
> The $pages object refers to a collection of pages. The pages in this collection can have the same or different parents, they can actually exist as subfolders in the content folder or be virtual pages …
