Skip to content

Instantly share code, notes, and snippets.

@arjenblokzijl
Last active December 15, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arjenblokzijl/5207400 to your computer and use it in GitHub Desktop.
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/.
<?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