wordpress-menu #56

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

View File

@ -33,6 +33,15 @@ chown -R www-data:www-data ./
## Arc-hive theme notes
### Configure
The main menu can be retrieved from a wordpress site and rendered. To configure this, edit `view/common/wordpress-menu.phtml`. Optional.
```
# Config
$wordpress_site="https://my.wordpress.site";
$wordpress_endpoint="https://my.wordpress.site/wp-json/menus/v1/menus/4";
```
For more advanced use, such as customizing the theme with Sass, you'll need to install the tools with [NodeJS](https://nodejs.org/en/) (0.12 or greater). Navigate to your theme directory and run `npm install`.

View File

@ -1,47 +1,57 @@
<?php
# Config
$wordpress_site="https://dev.arc-hive.zone";
$wordpress_endpoint="https://dev.arc-hive.zone/wp-json/menus/v1/menus/4";
use Zend\Http\Client;
$client = new Client('https://dev.arc-hive.zone/wp-json/menus/v1/menus/4');
$client->setOptions(array("timeout"=>1));
$response = $client->send();
$response_data = json_decode($response->getBody());
$items = new ArrayObject;
$items[0] = new ArrayObject();
$items[0] = new ArrayObject(); // top level menu items go here
if (!$response->isClientError()&& $response_data) {
foreach ($response_data as $menu_item) {
$item_url = $menu_item->url;
if (strtolower($menu_item->title) == 'login') {
$item_url = "/login";
if ($wordpress_endpoint) {
$client = new Client($wordpress_endpoint);
$client->setOptions(array("timeout"=>1));
$response = $client->send();
$response_data = json_decode($response->getBody());
if (!$response->isClientError() && $response_data) {
foreach ($response_data as $menu_item) {
$item_url = $menu_item->url;
if (strtolower($menu_item->title) == 'login') {
$item_url = "/login";
}
$item_title = $menu_item->title;
if (strtolower($menu_item->title) == 'collections') {
$item_title = "Project";
$item_url = $wordpress_site;
}
$item = [
"id" => $menu_item->ID,
"title" => $item_title,
"url" => $item_url
];
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;
}
$item = [
"ID" => $menu_item->ID,
"title" => $menu_item->title,
"url" => $item_url
];
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;
foreach ($items[$level_id] as $menu_item) {
echo '<li>' . PHP_EOL;
echo '<a href="'.$menu_item['url'].'">'.$menu_item['title'].'</a>' . PHP_EOL;
if (array_key_exists($menu_item['ID'], $items)) {
render_menu($items, $menu_item['ID']); // render sub menu
}
echo '</li>' . PHP_EOL;
function render_menu($items, $level_id) {
echo '<ul>' . PHP_EOL;
foreach ($items[$level_id] as $menu_item) {
echo '<li>' . PHP_EOL;
echo '<a href="'.$menu_item['url'].'">'.$menu_item['title'].'</a>' . PHP_EOL;
if (array_key_exists($menu_item['id'], $items)) {
render_menu($items, $menu_item['id']); // render sub menu
}
echo '</ul>' . PHP_EOL;
echo '</li>' . PHP_EOL;
}
echo '</ul>' . PHP_EOL;
}
render_menu($items, 0);