Jump to content

Child of Parent's Parent


Lance O.
 Share

Recommended Posts

Is there a more efficient way to code this using children($selector)?:

$ancestor = $pages->get( 1134 ); // Get the Section 1 page
$find = $pages->find( "parent=$ancestor->children, template=subcategory" );
$assets = $pages->find( "tag=$find, sort=title" );
if ( count( $assets ) ) {
foreach ( $assets as $asset ) {
	echo "<div class='asset'><a href='{$asset->url}'>{$asset->title}</a></div>";
}
}

The page hierarchy looks like this:

- Browse (the page that this code resides on)
   -- Section 1 (the ancestor page with id of 1134)
       --- Category 1
           ---- Subcategory 1
           ---- Subcategory 2
       --- Category 2
           ---- Subcategory 3
           ---- Subcategory 4
   -- Section 2
       --- Category 3
           ---- Subcategory 5
           ---- Subcategory 6
       --- Category 4
           ---- Subcategory 7
           ---- Subcategory 8
- Assets
   -- Asset 1 (tag = id of Subcategory 1)
   -- Asset 2 (tag = id of Subcategory 2)
   -- Asset 3 (tag = id of Subcategory 3)
   -- Asset 4 (tag = id of Subcategory 4)

I want to display all of the assets where tag = id of Subcategory 1, Subcategory 2, Subcategory 3, and Subcategory 4. In other words, I want to display all assets that are "included" in Section 1.

Link to comment
Share on other sites

I'm not sure I got your question right, but that doesn't seem very unefficient to me. The first two lines could be replaced by this though:

$find = $pages->find("has_parent=1134, template=subcategory");

So no need to get the ancestor first but go straight to find any page it's parent or grandparent of.

Maybe this was what you were after?

  • Like 3
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...