wordpress-menu #56
|
@ -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`.
|
||||
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
<?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');
|
||||
$items = new ArrayObject;
|
||||
$items[0] = new ArrayObject(); // top level menu items go here
|
||||
|
||||
if ($wordpress_endpoint) {
|
||||
$client = new Client($wordpress_endpoint);
|
||||
$client->setOptions(array("timeout"=>1));
|
||||
$response = $client->send();
|
||||
$response_data = json_decode($response->getBody());
|
||||
$items = new ArrayObject;
|
||||
$items[0] = new ArrayObject();
|
||||
|
||||
if (!$response->isClientError() && $response_data) {
|
||||
foreach ($response_data as $menu_item) {
|
||||
|
@ -15,9 +21,14 @@ if (!$response->isClientError()&& $response_data) {
|
|||
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" => $menu_item->title,
|
||||
"id" => $menu_item->ID,
|
||||
"title" => $item_title,
|
||||
"url" => $item_url
|
||||
];
|
||||
if (!array_key_exists($menu_item->menu_item_parent, $items)) {
|
||||
|
@ -26,23 +37,22 @@ if (!$response->isClientError()&& $response_data) {
|
|||
$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
|
||||
if (array_key_exists($menu_item['id'], $items)) {
|
||||
render_menu($items, $menu_item['id']); // render sub menu
|
||||
}
|
||||
echo '</li>' . PHP_EOL;
|
||||
}
|
||||
echo '</ul>' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
render_menu($items, 0);
|
||||
|
||||
|
|
Loading…
Reference in New Issue