wp-bootstrap-navwalker icon indicating copy to clipboard operation
wp-bootstrap-navwalker copied to clipboard

Help with wp-bootstrap-navwalker 2.1

Open SideQuestDIY opened this issue 12 years ago • 13 comments

Greetings Everyone,

I have been doing some thinking on some configurable options for version 2.1 of wp-bootstrap-navwalker and there are a few things I would like to tackle in this version.

  • [ ] Configurable Variables
  • [ ] Reworked Icon Support
  • [ ] Depth Limiter Override
  • [ ] Flat Menu Fix

Configurable Variables

I would like to establish a method for passing variables to the walker class. This will allow us to add configurable features (see Reworked Icon Support below) and better support modifications/extension of standard bootstrap features in WordPress.

The most elegant solution would be to pass the custom variables along with the wp_nav_menu declaration so features can be enabled or disabled on a per-menu basis.

<?php
    wp_nav_menu( array(
        'menu'             => 'primary',
        'theme_location'   => 'primary',
        'depth'            => 2,
        'container'        => 'div',
        'container_class'  => 'collapse navbar-collapse navbar-ex1-collapse',
        'menu_class'       => 'nav navbar-nav',
        'fallback_cb'      => 'wp_bootstrap_navwalker::fallback',
        'walker'           => new wp_bootstrap_navwalker(),

        //wp_bootstrap_navwalker Custom Args
        'limit_depth'      => false,
        'icon_support'     => true,
        'icon_prefix'      => 'glyphicon glyphicon-',
        'icon_slug'        => 'glyph-',
    ));
?>

I have been playing with this technique with mixed results. Sometimes you can access the custom variable from withing the start_el() function using this technique http://bit.ly/1kHL1qL

The variables are only accessible sometimes and I can't seem to figure out why. Can anyone lend a hand with passing the variables? or perhaps we can use a separate method such as adding hooks.

Reworked Icon Support

I would like to rework how icons are supported to add flexibility beyond glyphicons while still giving the use access to the title attribute. I preposte adding three configurable variables.

This will solve issue: #72

icon_support by default version 2.1 of the walker will be set to false, and will not try to output icons. We can use the icon_support variable to toggle support on a menu by menu basis, and if no icon is needed we can simply output the title attribute.

icon_prefix This will allow us the define the icon class prefix to be output in the html. Enabling support for other icon libraries.

icon_slug This variable would define an icon prefix to be used in the WordPress admin. Prefixing icons will allow us to search the title attribute for the slug and the trailing word to be used for icon output, while still allowing us to define a title attribute for the link.

Example: if 'icon_slug' => 'icon:' and we have a title attribute of icon:house Our Homepage we can search the string for the icon_slug and split the string and apply the icon prefix to the icon name while still outputting the title of Our Homepage

I also see this method being useful when you want to display an icon and disable the link, or add an icon to a menu header.

Depth Limiter Override

wp-bootstrap-navwalker is currently setup to only output to a menu depth of 2, as that is all that Bootstrap 3 supports. If you input a walker depth greater than 2 it currently hard limits you to a depth of 2. Although I don't recommend it, there are many people that have extended the css to include multiple dropdown levels and the limit_depth variable would allow you to manually override the hard limit.

Flat Menu Fix

wp-bootstrap-navwalker is currently does not output a link for any parents of a dropdown. This is the correct way to do it with bootstrap but should be overridden when the menu depth is set to 1, regardless of child items.

This will solve issue #57

Would anyone like to help?

If anyone would like to assist with the ongoing development an maintenance of wp-bootstrap-navwalker please let me know and I will look at adding you to the official contributors list and granting rights to manage the repo, as well as close issues.

Especially those already active in solving issues :) @cristovaov, @claudiosmweb, @mindctrl. @pattonwebz

If you are working on any enhancments make sure to submit a pull request to the dev branch: https://github.com/twittem/wp-bootstrap-navwalker/tree/dev

SideQuestDIY avatar Mar 10 '14 20:03 SideQuestDIY

@twittem // Hi Edward, Thanks for the thought, I certainly don't mind helping where/if I can. -Cris.

cristovaov avatar Mar 13 '14 15:03 cristovaov

Yes I want to help but do not have much time now. But I swear I will monitor, test and send pull requests.

claudiosanches avatar Mar 13 '14 16:03 claudiosanches

Awesome! @cristovaov & @claudiosmweb I have added you both as collaborators so you should now have read/write access to the repo. Thanks for helping out!

@claudiosmweb I see your in the WooThemes org now, does that mean you're a WooNinja?

SideQuestDIY avatar Mar 17 '14 15:03 SideQuestDIY

Totally up for helping out and contributing where I can.

+1 for the menu override idea - I've had 2 people contact me in as many weeks for help getting a 3rd level of menu to show up.

I've got a couple of hours spare this week - I only planned to waste them on twitter and youtube anyway haha! - so lay a couple of tasks on me :).

pattonwebz avatar Mar 17 '14 16:03 pattonwebz

@pattonwebz perfect! I have added you as a contributor as well. I Think the first major task is figuring out how to pass variables to the walker. I feel the most elegant solution would be if we can pass them from the wp_nav_menu() function or in the functions.php. Once we have vars being passed everything should fall into place quite quickly.

SideQuestDIY avatar Mar 17 '14 16:03 SideQuestDIY

That's weird that the variables are only accessible sometimes through start_el() and not other times. I'm gonna take a look at that shortly and see if I can find a reason for it working that way.

My initial thoughts are that there could be some inadvertent caching going on somewhere - possibly opcode caching server-side but we'll see.

Like you said - if we can crack the passing of $vars then everything else should be a lot easier.

pattonwebz avatar Mar 17 '14 17:03 pattonwebz

I just realized in the screen options for the menus page there is an option for CSS classes.

css-classes

I am going to work on reworking the additions: disabling links, nav headers & icons into the class field. The dividers will still work off the Navigation Label field.

SideQuestDIY avatar Mar 18 '14 17:03 SideQuestDIY

Speaking of the 'CSS Class' field, I've been thinking about the icons issue: adding an 'Icon' option in the 'Menus' screen (like the 'css classes' field ie.), making the WP-Bootstrap-Nav independent of any custom icon font. My first attempt this weekend was unsuccessful but I think I should be able to make it work with more time. What do you think @twittem ?.

cristovaov avatar Mar 18 '14 18:03 cristovaov

@cristovaov I think thats a great idea, if we can work it out that would be a great method. My original thought with adding the icon_slug variable was that we could but all of the extras into the css class and then search the string for the slug. So if the slug was icon- and we searched the string to extract icon-home but I feel this is way too complicated.

I like your method the best. Then in the wp_nav_menu arguments we can define that font library type. I'm thinking we will build support for Glyphicons and Font Awesome into the script, then create a hook where you can add your own as we need to be able to change the HTML output for every icon type. As they are slightly different as illustrated below.

Glyphicon <span class="glyphicon glyphicon-star"></span>

Font Awesome <i class="fa fa-rub"></i>

SideQuestDIY avatar Mar 19 '14 15:03 SideQuestDIY

Hello.

Now I'm working on justified navigation based on this walker. It looks like this like this:

nav-walker-justify

I use additional class "dropdown-submenu", 15 lines JS and small changes in the template. If I'm might some help, it would be great.

But I did not always have the opportunity to make changes quickly.

artbelov avatar Mar 20 '14 05:03 artbelov

@twittem I've got the icons option to work. In this first draft the full icon markup is submitted, only requiring a very small deletion in the walkers' output. Validation/sanitisation still needs to be implemented, hope I figure it out this weekend -or else put the mods without for the moment. Got you a screenshot in the meantime > fireshot screen capture 006 - menus cristovao verstraeten wordpress - wptrunk_dev_wordpress_wp-admin_nav-menus_php
fireshot screen capture 009 - cristovao verstraeten i tailored wordpress development services - wptrunk_dev

cristovaov avatar Mar 22 '14 01:03 cristovaov

any update in the 3 depth custom css needed? with the 'limit_depth' => false,

cuttingedgehobbies avatar Nov 10 '15 23:11 cuttingedgehobbies

In the interest of clearing out older or inactive issues to focus on active ones; I'm closing this for now.

I have made an attempt to deal with several of the items in the opening post in a future version of the walker. If we are to reopen this we should also add it to a project/roadmap/milestone for tracking.

pattonwebz avatar Jul 06 '17 14:07 pattonwebz