Jump to content

Obtain a nav tree


buothz
 Share

Recommended Posts

I'm creating a menu for a site, I need to take pages url and title as follows

STUDENTS

MALE

PETER

JACOB

ALDO

FEMALE

ANNA

FRANCESCA

I need to take up the third child

1st node STUDENTS

2nd node MALE/FEMALE

3rd node PETER/JACOB...

if u use this code

$sc = $pages->get("/students/");
   $children = $sc->children;

   echo '<ul>';
   foreach($children as $child) {
 $child === $page->rootParent;
 echo "<li><a href='{$child->url}'>{$child->title}</a></li>";
   }
   echo '</ul>';

I obtain MALE/FEMALE, how I can take PETER/JACOB and others???

thank u

Link to comment
Share on other sites

You want all of them? Male and female?

You could put another foreach inside the one you have, but would be more practical to give those pages the same template and call them by it:

$pages->find("template=people")
  • Like 1
Link to comment
Share on other sites

echo "<ul>";
foreach($pages->get("/students/")->children) as $gender) {
 echo "<li><a href='{$gender->url}'>{$gender->title}</a><ul>"; // Male or Female
 foreach($gender->children as $student) {
   echo "<li><a href='{$student->url}'>{$student->title}</a></li>"; // Peter, Anna, etc.
 }
 echo "</ul></li>";
}
echo "</ul>";
  • Like 1
Link to comment
Share on other sites

echo "<ul>";
foreach($pages->get("/students/")->children) as $gender) {
 echo "<li><a href='{$gender->url}'>{$gender->title}</a><ul>"; // Male or Female
 foreach($gender->children as $student) {
echo "<li><a href='{$student->url}'>{$student->title}</a></li>"; // Peter, Anna, etc.
 }
 echo "</ul></li>";
}
echo "</ul>";

thank u a lot.. tomorrow i'll try the code... I thought there was another method using the Processwire API ;)

Link to comment
Share on other sites

echo "<ul>";
[color=#ff0000]foreach($pages->get("/students/")->children) as $gender) { GIVE ERROR, now I'll try to do [/color]$sc = $pages->get("/students/");
 echo "<li><a href='{$gender->url}'>{$gender->title}</a><ul>"; // Male or Female
 foreach($gender->children as $student) {
echo "<li><a href='{$student->url}'>{$student->title}</a></li>"; // Peter, Anna, etc.
 }
 echo "</ul></li>";
}
echo "</ul>";

give me error

"Parse Error syntax error, unexpected ')' (line 224 of /home/mhd-01/www.cosascegli.it/htdocs/site/templates/head.inc)

This error message was shown because you are logged in as a Superuser. Error has been logged."

Link to comment
Share on other sites

There is unnecessary ) on Ryan's example after first children.

This line:

foreach($pages->get("/students/")->children) as $gender) {

should be:

foreach($pages->get("/students/")->children as $gender) {
  • Like 1
Link to comment
Share on other sites

There is unnecessary ) on Ryan's example after first children.

This line:

foreach($pages->get("/students/")->children) as $gender) {

should be:

foreach($pages->get("/students/")->children as $gender) {

i've used this code

//menu con pagine fino a terzo figlio   
   $yc = $pages->get("/yachts/");
   $children = $yc->children;
   $childchildren = $child->children;
   //$children->prepend($yc); mi restituisce yacht
   echo '<ul>';
   foreach($children as $child) {
 $child === $page->rootParent; //=== identico, == equal
 echo "<li><a href='{$child->url}'>{$child->title}</a></li><ul>";

 foreach($child->children as $schild) {
  echo "<li><a href='{$schild->url}'>{$schild->title}</a></li>";
  }
 echo '</ul></li>';
   }
   echo '</ul>';
   //fine menu fino a terzo figlio
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...