Jump to content

Recommended Posts

Posted

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)
Posted

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");
Posted

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?

Posted

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");
  • Like 5
  • 5 months later...
Posted

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,

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...