Last active
December 15, 2015 05:09
-
-
Save arjenblokzijl/5207400 to your computer and use it in GitHub Desktop.
Example of how to add children to the homepage in ProcessWire. See: http://processwire.com/talk/topic/3065-direct-children-of-default-front-page/.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get the homepage | |
$homepage = $pages->get("/"); | |
// Get the all the children of home | |
$children = $homepage->children; | |
// Get all the homepage children who need to be under home in the menu | |
$homePageChildren = $homepage->children("homechild=1"); | |
// Remove the children you want to use as homepage | |
$children = $children->not("homechild=1"); | |
// Store this in a variable so you can output it later | |
$homeMenu = "<ul>"; | |
// Loop through the homepage children and store them in the var | |
foreach($homePageChildren as $homePageChild) { | |
$homeMenu .= "<li><a href='{$homePageChild->url}'>{$homePageChild->title}</a></li>"; | |
} | |
$homeMenu .= "</ul>"; | |
// Start the actual menu here | |
echo "<ul>"; | |
// Create the link to home and output the $homeMenu | |
echo "<li><a href='{$homepage->url}'>{$homepage->title}</a>{$homeMenu}</li>"; | |
// Loop through the normal children | |
foreach($children as $child) { | |
echo "<li><a href='{$child->url}'>{$child->title}</a></li>"; | |
} | |
echo "</ul>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment