wordpress-menu #56

Merged
chris merged 49 commits from wordpress-menu into develop 2022-03-25 13:12:29 +01:00
3 changed files with 70 additions and 9 deletions
Showing only changes of commit 3f42b2f218 - Show all commits

View File

@ -18,12 +18,13 @@
</main>
<nav>
<menu class="">
<?php /*
<?php
echo $site->publicNav()
->menu()
->setPartial('common/foundation-navigation.phtml')
->setPartial('common/wordpress-menu.phtml')
->renderPartialWithParams(['layout' => 'dropdown']);
*/
?>
</menu>
</nav>

View File

@ -42,12 +42,10 @@ $img_src = null;
<nav>
<menu class="">
<?php //
// Segun el diseño, este menu no existe
// ----------
// echo $site->publicNav()
// ->menu()
// ->setPartial('common/foundation-navigation.phtml')
// ->renderPartialWithParams(['layout' => 'dropdown']);
echo $site->publicNav()
->menu()
->setPartial('common/wordpress-menu.phtml')
->renderPartialWithParams(['layout' => 'dropdown']);
?>
</menu>
</nav>

View File

@ -0,0 +1,62 @@
<?php
use Zend\Http\Client;
$client = New Client;
$client = new Client('https://dev.arc-hive.zone/wp-json/menus/v1/menus/4');
$response = $client->send();
$response_items = json_decode($response->getBody());
$items = new ArrayObject();
foreach ($response_items as $menu_item) {
$item_url = $menu_item->url;
if (strtolower($menu_item->title) == 'login') {
$item_url = "/login";
}
$item = [
"ID" => $menu_item->ID,
"title" => $menu_item->title,
"url" => $item_url,
"menu_item_parent" => $menu_item->menu_item_parent,
];
if (!array_key_exists($menu_item->menu_item_parent, $items)) {
$items[$menu_item->menu_item_parent] = new ArrayObject();
}
$items[$menu_item->menu_item_parent][$menu_item->ID] =$item;
}
//print_r($items);
if (!function_exists('menu_level_items')) {
function menu_level_items($items, $level_id) {
$level_items = new ArrayObject();
foreach ($items as $menu_level) {
foreach ($menu_level as $menu_item) {
if ($menu_item['menu_item_parent'] == $level_id) {
$level_items->append($menu_item);
}
}
}
return $level_items;
}
}
if (!function_exists('render_menu')) {
function render_menu($items, $level_id) {
$level_items = menu_level_items($items, $level_id);
echo '<ul>' . PHP_EOL;
foreach ($level_items as $menu_item) {
echo '<li>' . PHP_EOL;
echo '<a href="'.$menu_item['url'].'">'.$menu_item['title'].'</a>' . PHP_EOL;
if (menu_level_items($items, $menu_item['ID'])) {
render_menu($items, $menu_item['ID']); // render sub menu
}
echo '</li>' . PHP_EOL;
}
echo '</ul>' . PHP_EOL;
}
}
render_menu($items, 0);
?>