Jump to content

Rendernav issue


howsoonisnow90
 Share

Recommended Posts

Hello everyone ? I've got an issue related to the renderNav function.. 

I need to print out just the children of a specific page, for example with id = '0108', how do I do it? 
And for every children I'd need to print it out with an image and contents like 'title' 'headline' etc. associated. 

thank you so much ?

 

 

Link to comment
Share on other sites

Hi @howsoonisnow90

<?php

$root = $pages->get(1);

$children = $root->children;

echo "<ul>";

foreach($children as $child) {

  if($child->id == 0108) {

      echo "<li>$child->title";

     echo "<ul>";

   foreach($child->children as $grandchild) {

    echo "<li>$grandchild->title</li>";

  echo "</ul>";
     
  echo "</li>";

   } else {

   echo "<li>$child->title</li>";

  }

  }

}

echo "</ul>";

Hope this helps.

Gideon

Link to comment
Share on other sites

@Gideon So,

Please correct your code. It is broken in several places (missing braces, etc.). For instance:

57 minutes ago, Gideon So said:
  if($child->id == 0108) {

      echo "<li>$child->title</li>";

     echo "<ul>";

Here you close </li> early, before its children (nested ul). 

59 minutes ago, Gideon So said:
$root = $page->get(1);

I think you meant $pages->get(1) ?.

  • Like 1
Link to comment
Share on other sites

it doesn't work, it gives me these errors: 

Notice:  Undefined variable: root in /Applications/MAMP/htdocs/realwanderlust/site/assets/cache/FileCompiler/site/templates/viaggi.php on line 89

Notice:  Trying to get property 'children' of non-object in /Applications/MAMP/htdocs/realwanderlust/site/assets/cache/FileCompiler/site/templates/viaggi.php on line 89

Warning:  Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/realwanderlust/site/assets/cache/FileCompiler/site/templates/viaggi.php on line 91

Link to comment
Share on other sites

7 hours ago, howsoonisnow90 said:

it doesn't work, it gives me these errors: 

Notice:  Undefined variable: root in /Applications/MAMP/htdocs/realwanderlust/site/assets/cache/FileCompiler/site/templates/viaggi.php on line 89

Notice:  Trying to get property 'children' of non-object in /Applications/MAMP/htdocs/realwanderlust/site/assets/cache/FileCompiler/site/templates/viaggi.php on line 89

Warning:  Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/realwanderlust/site/assets/cache/FileCompiler/site/templates/viaggi.php on line 91

Hi @howsoonisnow90,

I have updated the code. Please try the updated one.

Gideon

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

  • Recently Browsing   0 members

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