Jump to content


Photo

Obtain a nav tree

nav menu navigation

  • Please log in to reply
6 replies to this topic

#1 buothz

buothz

    Jr. Member

  • Members
  • PipPip
  • 45 posts
  • 3

Posted 30 May 2012 - 01:39 PM

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

#2 diogo

diogo

    Hero Member

  • Moderators
  • 2,006 posts
  • 1081

  • LocationPorto, Portugal

Posted 30 May 2012 - 03:46 PM

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


#3 ryan

ryan

    Hero Member

  • Administrators
  • 5,773 posts
  • 3122

  • LocationAtlanta, GA

Posted 31 May 2012 - 10:17 AM


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



#4 buothz

buothz

    Jr. Member

  • Members
  • PipPip
  • 45 posts
  • 3

Posted 02 June 2012 - 05:00 PM

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

#5 buothz

buothz

    Jr. Member

  • Members
  • PipPip
  • 45 posts
  • 3

Posted 03 June 2012 - 03:08 AM

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."

#6 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,526 posts
  • 854

  • LocationVihti, Finland

Posted 03 June 2012 - 03:16 AM

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


#7 buothz

buothz

    Jr. Member

  • Members
  • PipPip
  • 45 posts
  • 3

Posted 03 June 2012 - 06:45 AM

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users