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>";
}
?>