From f79b7af69c4630ed42f7b8179748a62ec13c1ce6 Mon Sep 17 00:00:00 2001 From: buttle Date: Fri, 25 Mar 2022 10:58:33 +0100 Subject: [PATCH] adds config, and config instructions. --- README.md | 9 ++++ view/common/wordpress-menu.phtml | 70 ++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index aadb5a9..9376d14 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/view/common/wordpress-menu.phtml b/view/common/wordpress-menu.phtml index 04e6244..248f45c 100644 --- a/view/common/wordpress-menu.phtml +++ b/view/common/wordpress-menu.phtml @@ -1,47 +1,57 @@ 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 '' . PHP_EOL; } render_menu($items, 0);