howsoonisnow90 Posted November 8, 2021 Share Posted November 8, 2021 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 More sharing options...
Gideon So Posted November 8, 2021 Share Posted November 8, 2021 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 More sharing options...
kongondo Posted November 8, 2021 Share Posted November 8, 2021 @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) ?. 1 Link to comment Share on other sites More sharing options...
howsoonisnow90 Posted November 8, 2021 Author Share Posted November 8, 2021 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 More sharing options...
Gideon So Posted November 9, 2021 Share Posted November 9, 2021 16 hours ago, kongondo said: @Gideon So, Please correct your code. It is broken in several places (missing braces, etc.). For instance: Here you close </li> early, before its children (nested ul). I think you meant $pages->get(1) ?. Hi @kongondo, Thanks for checking my code. Have just updated it. Gideon Link to comment Share on other sites More sharing options...
Gideon So Posted November 9, 2021 Share Posted November 9, 2021 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 More sharing options...
howsoonisnow90 Posted November 9, 2021 Author Share Posted November 9, 2021 hey Gideon, thank you, I still see the old code! Link to comment Share on other sites More sharing options...
howsoonisnow90 Posted November 9, 2021 Author Share Posted November 9, 2021 13 hours ago, Gideon So said: Hi @howsoonisnow90, I have updated the code. Please try the updated one. Gideon it worked!! just changed a few things and it's now working, thanks a lot guys!! 1 Link to comment Share on other sites More sharing options...
kongondo Posted November 9, 2021 Share Posted November 9, 2021 2 hours ago, howsoonisnow90 said: it worked!! just changed a few things and it's now working, thanks a lot guys!! Glad you got it sorted ?. Link to comment Share on other sites More sharing options...
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