ngrmm Posted November 23, 2015 Share Posted November 23, 2015 this is my code $gp = $pages->get(1016); $children = $gp->children; foreach($children as $child) { $articles = $child->children; foreach($articles as $article) { … } } i want all articles to be sorted by title (asc) i tried this: $articles = $child->children('sort=title'); but the sorting happened too early an this doesn't work also (too early) foreach($articles->sort('name') as $article) Link to comment Share on other sites More sharing options...
diogo Posted November 23, 2015 Share Posted November 23, 2015 The secret is to adapt the selector to get all the pages in one go. Try this: $gp = $pages->get(1016); $children = $gp->children; $articles = $pages->get("parent={$children}, sort=title"); Link to comment Share on other sites More sharing options...
ngrmm Posted November 23, 2015 Author Share Posted November 23, 2015 thx diogo $gp = $pages->get(1016); $children = $gp->children; $articles = $pages->get("parent={$children}, sort=title"); foreach($articles as $article) { echo $article->title; } but it doesn't work maybe because $children is an array? Link to comment Share on other sites More sharing options...
kixe Posted November 23, 2015 Share Posted November 23, 2015 The secret is to create a nice selector and use the API correctly. $pages->get() returns a single page, whereas $pages->find() returns a page array. /** * has_parent=1016 selects all children and grandchildren of the page with id = 1016 * parent!=1016 excludes the children (first generation) **/ $articles = $pages->find("has_parent=1016,parent!=1016,sort=title"); 5 Link to comment Share on other sites More sharing options...
diogo Posted November 23, 2015 Share Posted November 23, 2015 Oops sorry, I had a get where it should be a find. 1 Link to comment Share on other sites More sharing options...
psquaretrader Posted April 28, 2016 Share Posted April 28, 2016 Hello, I have a parent page template that i'm attempting to make the parent page content be a list of the title/links of all of the parent's children and have it sort the output in alphabetical order. this is the template: <?php // basic-page.php template file // See README.txt for more information // Primary content is the page's body copy $content = renderNavTree($page->children ("sort=Title")); The Problem is that the rendering of the page does not list the children in alphabetical order. Can you help me understand. thanks, Link to comment Share on other sites More sharing options...
Christophe Posted April 28, 2016 Share Posted April 28, 2016 Hello, Try by using title instead of Title. 2 Link to comment Share on other sites More sharing options...
psquaretrader Posted April 29, 2016 Share Posted April 29, 2016 Thanks Christophe, that worked! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now