Instantly share code, notes, and snippets.
Last active
May 25, 2016 17:24
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save thesjg/607bfdf701d9276d6bf806c59ef7e087 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{#has_container}} | |
{{#if has_container_id_class}} | |
<{{container}} id="{{container_id}}" class="{{container_class}}"> | |
{{else if has_container_id}} | |
<{{container}} id="{{container_id}}"> | |
{{else if has_container_class}} | |
<{{container}} class="{{container_class}}"> | |
{{else}} | |
<{{container}}> | |
{{/if}} | |
{{/has_container}} | |
{{#if has_menu_id_class}} | |
<ul id="{{menu_id}}" class="{{menu_class}}"> | |
{{else if has_menu_id}} | |
<ul id="{{menu_id}}"> | |
{{else if has_menu_class}} | |
<ul class="{{menu_class}}"> | |
{{else}} | |
<ul> | |
{{/if}} | |
<li class="nav-item"><a class="nav-link btn btn-lg btn-error" href="{{wp_admin_url path='nav-menus.php'}}">Create or Assign <strong><em>{{menu_theme_location}}</em></strong></a></li> | |
</ul> | |
{{#has_container}} | |
</{{container}}> | |
{{/has_container}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li class="nav-item {{classes}}"> | |
<a class="nav-link" href="{{url}}"{{# has_target}} target="{{target}}"{{/has_target}}{{# has_attr_title}}{{attr_title}}{{/ has_attr_title}}>{{title}}</a> | |
</li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Dreamery\WP; | |
/* PHP */ | |
use Exception; | |
/* WP Global */ | |
use Walker; | |
use Dreamery\Template; | |
class NavMenuWalker extends Walker { | |
public $tree_type = array('post_type', 'taxonomy', 'custom'); | |
/** | |
* Database fields to use, same as the default WordPress Walker_Nav_Menu class | |
*/ | |
public $db_fields = array('parent' => 'menu_item_parent', 'id' => 'db_id'); | |
private $newLevel = null; | |
public function start_lvl(&$output, $depth = 0, $args = array()) { | |
echo 'start_lvl()<br>'; | |
$this->newLevel = true; | |
$this->elements = array(); | |
} | |
public function end_lvl(&$output, $depth = 0, $args = array()) { | |
echo 'end_lvl()<br>'; | |
/* | |
* Render level and all child elements | |
*/ | |
/* | |
$output .= '<ul>'; | |
$output .= $this->$elements; | |
$output .= '</ul>'; | |
*/ | |
$this->newLevel = true; | |
return $output; | |
} | |
public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { | |
echo 'start_el()<br>'; | |
if ($this->newLevel === null) | |
$this->newLevel = true; | |
/* | |
* Build Element | |
*/ | |
$this->newLevel = false; | |
} | |
public function end_el(&$output, $item, $depth = 0, $args = array()) { | |
echo 'end_el()<br>'; | |
$t = new Template(); | |
$options = array( | |
'url' => $item->url, | |
'title' => $item->title, | |
'target' => $item->target, | |
'has_target' => (empty($item->target)) ? false : true, | |
'classes' => implode(' ', $item->classes), | |
'attr_title' => $item->attr_title, | |
'has_attr_title' => (empty($item->attr_title)) ? false : true, | |
); | |
$output .= $t->render('navigation-menu-element', $options); | |
} | |
public function walk($elements, $max_depth) { | |
$output = parent::walk($elements, $max_depth); | |
return $output; | |
} | |
/* | |
* | |
* YYY: | |
* Does something need to be done with before, after, link_before, link_after, or items_wrap | |
* as passed to us in $args? | |
*/ | |
public static function fallback($args) { | |
if (current_user_can('manage_options')) { | |
$options = array_intersect_key($args, array('container' => true, 'container_id' => true, | |
'container_class' => true, 'menu_id' => true, 'menu_class' => true)); | |
$options['has_container'] = (empty($options['container'])) ? false : true; | |
$options['has_container_id_class'] = false; | |
$options['has_container_id'] = false; | |
$options['has_container_class'] = false; | |
if (!empty($options['container_id']) && !empty($options['container_class'])) | |
$options['has_container_id_class'] = true; | |
if (!empty($options['container_id'])) | |
$options['has_container_id'] = true; | |
if (!empty($options['container_class'])) | |
$options['has_container_class'] = true; | |
$options['has_menu_id_class'] = false; | |
$options['has_menu_id'] = false; | |
$options['has_menu_class'] = false; | |
if (!empty($options['menu_id']) && !empty($options['menu_class'])) | |
$options['has_menu_id_class'] = true; | |
if (!empty($options['menu_id'])) | |
$options['has_menu_id'] = true; | |
if (!empty($options['menu_class'])) | |
$options['has_menu_class'] = true; | |
$menus = get_registered_nav_menus(); | |
$options['menu_theme_location_ident'] = $args['theme_location']; | |
$options['menu_theme_location'] = $menus[$options['menu_theme_location_ident']]; | |
// get compiler | |
$t = new Template(); | |
echo $t->render('navigation-menu-default', $options); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment