Arc-hive-omeka-theme/view/common/wordpress-menu.phtml

48 lines
1.2 KiB
PHTML
Raw Normal View History

2022-03-24 22:42:29 +01:00
<?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('render_menu')) {
function render_menu($items, $level_id) {
echo '<ul>' . PHP_EOL;
2022-03-25 10:00:24 +01:00
foreach ($items[$level_id] as $menu_item) {
2022-03-24 22:42:29 +01:00
echo '<li>' . PHP_EOL;
echo '<a href="'.$menu_item['url'].'">'.$menu_item['title'].'</a>' . PHP_EOL;
2022-03-25 10:00:24 +01:00
if (array_key_exists($menu_item['ID'], $items)) {
2022-03-24 22:42:29 +01:00
render_menu($items, $menu_item['ID']); // render sub menu
}
echo '</li>' . PHP_EOL;
}
echo '</ul>' . PHP_EOL;
}
}
render_menu($items, 0);
?>