wordpress-menu #56
|
@ -33,6 +33,15 @@ chown -R www-data:www-data ./
|
||||||
|
|
||||||
## Arc-hive theme notes
|
## 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`.
|
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,47 +1,57 @@
|
||||||
<?php
|
<?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;
|
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 = new ArrayObject;
|
||||||
$items[0] = new ArrayObject();
|
$items[0] = new ArrayObject(); // top level menu items go here
|
||||||
|
|
||||||
if (!$response->isClientError()&& $response_data) {
|
if ($wordpress_endpoint) {
|
||||||
foreach ($response_data as $menu_item) {
|
$client = new Client($wordpress_endpoint);
|
||||||
$item_url = $menu_item->url;
|
$client->setOptions(array("timeout"=>1));
|
||||||
if (strtolower($menu_item->title) == 'login') {
|
$response = $client->send();
|
||||||
$item_url = "/login";
|
$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);
|
//print_r($items);
|
||||||
|
|
||||||
if (!function_exists('render_menu')) {
|
function render_menu($items, $level_id) {
|
||||||
function render_menu($items, $level_id) {
|
echo '<ul>' . PHP_EOL;
|
||||||
echo '<ul>' . PHP_EOL;
|
foreach ($items[$level_id] as $menu_item) {
|
||||||
foreach ($items[$level_id] as $menu_item) {
|
echo '<li>' . PHP_EOL;
|
||||||
echo '<li>' . PHP_EOL;
|
echo '<a href="'.$menu_item['url'].'">'.$menu_item['title'].'</a>' . PHP_EOL;
|
||||||
echo '<a href="'.$menu_item['url'].'">'.$menu_item['title'].'</a>' . PHP_EOL;
|
if (array_key_exists($menu_item['id'], $items)) {
|
||||||
if (array_key_exists($menu_item['ID'], $items)) {
|
render_menu($items, $menu_item['id']); // render sub menu
|
||||||
render_menu($items, $menu_item['ID']); // render sub menu
|
|
||||||
}
|
|
||||||
echo '</li>' . PHP_EOL;
|
|
||||||
}
|
}
|
||||||
echo '</ul>' . PHP_EOL;
|
echo '</li>' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
echo '</ul>' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
render_menu($items, 0);
|
render_menu($items, 0);
|
||||||
|
|
Loading…
Reference in New Issue