Jump to content

congomonster_616

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by congomonster_616

  1. Hi BrendonKoz, thank you for your answer! I came up with a solution by myself. But i will use your solution! Your code is smaller than mine! ? My solution was also that i changed wire('page') to wire('pages'). Then i choosed the page->get() <?php namespace ProcessWire; function navigationold() { $pages = wire("pages"); $page = wire("page"); echo "<ul class='navbar-nav my-3 my-lg-0 fw-semibold rounded'>"; $sites = $pages->get('home')->children(); foreach ($sites as $item) { // set the active class $active_link=""; if ($page->id == $item->id) { $active_link="nav-link active p-3"; } else { $active_link="nav-link p-3"; } echo "<li class='nav-item'><a href='". $item->url ."' class='" . $active_link . "'>" . $item->title . "</a><li>"; } echo "</ul>"; } ?> <?php navigationold(); ?> But then i tried to use your code and changed thinks for me: <?php function navigation() { echo "<ul class='navbar-nav my-3 my-lg-0 fw-semibold rounded'>"; foreach (wire('pages')->get(1)->children as $homepage) { if (!wire('page') == $homepage) { continue; // Skip to the next iteration of the loop } else { // Place your navigation generating code here, except if you use this, change $page in your code above to $homepage echo "<li class='nav-item'><a href='". $homepage->url ."' class='nav-link p-3"; if (wire('page')->id == $homepage->id) {echo " active";} echo "'>". $homepage->title ."</a></li>"; } } echo "</ul>"; } ?> <?php navigation(); ?> This looks really good so far. Next step for me is to show a homepage link to. Thank you! ?
  2. Hi, after a long time i use processwire again. But i have a problem and can't get a solution. I have build a navigation. I have to reuse this part. So i thought, i could write a function. I have searched the forum and i learned that i have to use wire() to get access to the sites inside the function. My problem is now, that everytime i click on a new site (children of home), the menu only shows the current page and there children. I know, that's what i have coded. ? Without the function i could use $home to get the root site and the children. How can i acess always the root page in the function? And display all the sites? I tried to get wire("pages") instead, but i don't know how tu use the object. I would be really thankful if someone shows me the right direction. <?php namespace ProcessWire; function navigation() { $page = wire("page"); echo "<ul class='navbar-nav my-3 my-lg-0 fw-semibold rounded'>"; foreach ($page->and($page->children()) as $item) { // set the active class $active_link=""; if ($page->id == $item->id) { $active_link="nav-link active p-3"; } else { $active_link="nav-link p-3"; } echo "<li class='nav-item'><a href='". $item->url ."' class='" . $active_link . "'>" . $item->title . "</a><li>"; } echo "</ul>"; } ?>
×
×
  • Create New...