ngrmm Posted November 23, 2015 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)
diogo Posted November 23, 2015 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");
ngrmm Posted November 23, 2015 Author 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?
kixe Posted November 23, 2015 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
diogo Posted November 23, 2015 Posted November 23, 2015 Oops sorry, I had a get where it should be a find. 1
psquaretrader Posted April 28, 2016 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,
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