# Page depth below specific parent

**URL:** <https://forum.getkirby.com/t/page-depth-below-specific-parent/7416>\
**Category:** Questions\
**Tags:** v2\
**Created:** [May 5, 2017, 2:40pm UTC](https://forum.getkirby.com/t/page-depth-below-specific-parent/7416 "2017-05-05T14:40:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fitzage](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/fitzage/32/4217_2.png) [@fitzage](https://forum.getkirby.com/u/fitzage)\
**Post date:** [May 5, 2017, 2:40pm UTC](https://forum.getkirby.com/t/page-depth-below-specific-parent/7416/1 "2017-05-05T14:40:51Z")

</div>

I’m building out a kind of microsite that I want to be able to be plugged in anywhere at any page depth and still work. I’ve got some very important help from @texnixe (as seen here [Passing field value/variable to child pages - #7 by texnixe](https://forum.getkirby.com/t/passing-field-value-variable-to-child-pages/7245/7)), which is awesome.

The new challenge is figuring out how to get page depth but base it on a specific parent page, so that I can have depth-based settings that work no matter what depth the whole sub-structure is located at. This could possibly build off of the previous thread, which tells me which page I have set as my top-level page for this microsite.

What would be really cool is if I could pass a parent page to `$page->depth()` and get the depth below that parent. But that doesn’t seem to currently be a thing.

I can get a count of parent pages with `$page->parents()->count()`, but I need a way to stop that at the specific page I’m looking for so I can get depth below that. Any ideas?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 5, 2017, 3:02pm UTC](https://forum.getkirby.com/t/page-depth-below-specific-parent/7416/2 "2017-05-05T15:02:53Z")

</div>

`$page->parents()` gives you an array of all the parents. You can get the key of a specific page using `indexOf()`:

```auto
$page->parents()->indexOf('somepage');

```

An index of 0 would be the immediate parent of the page etc. You should be able to work it from there, taking the number of elements in the array into account?

---

<div class="post-metadata">

**Author:** ![fitzage](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/fitzage/32/4217_2.png) [@fitzage](https://forum.getkirby.com/u/fitzage)\
**Post date:** [May 5, 2017, 3:45pm UTC](https://forum.getkirby.com/t/page-depth-below-specific-parent/7416/3 "2017-05-05T15:45:20Z")

</div>

Excellent. Using that in combination with the page method you provided from the other thread gives me exactly what I need.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:50pm UTC](https://forum.getkirby.com/t/page-depth-below-specific-parent/7416/4 "2025-02-06T16:50:03Z")

</div>

Archived on February 6, 2025, 4:50pm UTC


