Jump to content

Robin S
 Share

Recommended Posts

This module fulfills a need that's perhaps not common but there have been some requests for it in the past. There's an open request in the requests repo so the features might get added to the core at some point but for now here's a module for anyone who needs it.

PageFinder Depth

Adds the ability to find and sort pages by the depth of the page relative to the home page. The module requires that the core PagePaths module is installed.

Depth of a page in this case means the same thing as "number of parents", so a page that is directly under the home page has a depth of 1, and a child of that page has a depth of 2, and so on.

If you already have a Page object you can get its depth with $page->numParents() but the result of this isn't searchable in a PageFinder selector. Installing this module allows you to use selectors like this:

$items = $pages->find("depth=2");

$items = $pages->find("template=basic-page, depth>1, depth<4");

$items = $pages->find("template=product, sort=depth");
 

The keyword "depth" is configurable in the module settings so you can change it to something different if you already have a field named "depth" that the default keyword would clash with.

Limitations

OR-group selectors are not supported for depth.

Searching by depth in an existing PageArray

This module only adds features for PageFinder selectors and doesn't automatically add any depth property to Page objects in memory, but you can search within a PageArray using numParents to achieve the same thing, e.g.

$items = $my_pagearray->find("template=basic-page, numParents>1, numParents<4");

 

https://github.com/Toutouwai/PageFinderDepth

  • Like 6
  • Thanks 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...