Additional Options: Add WP menu, Only Show on scroll
-
I must say I like your plugin. It’s cool and neat.
I came across this plugin http://wordpress.org/plugins/sticky-notification-bar/ It has a few cool features but not looking as slick as yours.
1) The bar only show upon scrolling. This is nice because yours hide my top menu.
2) You can define a pre created menu and it shows the links in the bar.
3) You can add social buttons.
What is not so neat is the look of the bar and the fact that they plugged a link to their site onto the bar.
I would like to ask to consider the first two options for the feature.
-
For #1 —
The would mean a jquery change to capture the scroll() event. Let me look at the for a future change.
For #2 —
In your functions.php file add this code to create a custom menu. Then use the standard WordPress Appearance | Menu to create the menu:
//register the custom menus function register_wptopbar_menus() { register_nav_menus( array( 'wptopbar-menu' => __( 'TopBar Menu' ) ) ); } add_action( 'init', 'register_wptopbar_menus' );In the PHP (Prefix or Suffix – your choice)… use this code:
wp_nav_menu(array('menu'=>'wptopbar-menu' ));Ok – for #1 — I have it coded for the next release.
Did #2 work for you?
Bob
Hi Bob
Thanks. I am looking forward to the new release.
I will do the menu today. And let you know.Have fun
Hi Bob
Would it be possible to add this menu idea to your plugin as I am worried that when I install a new version of WP then I need to remember to add this. Or is there another way around this update issue?
Thanks
Your functions.php is in your theme folder and is not changed when you upgrade WordPress. It is only affected when you upgrade/change your theme.
I’ll have to walk through the various use cases and implications before I add this to the plugin. For example, do I allow each TopBar to have its own menu? If so, that can create dozens of menus to populate? Do I let have all TopBar’s share one? I have to work through all of those and then test them. So, it won’t be in the next release.
Understood. Can I add this in a child theme then you don’t have to worry about it. Thanks for the support. It’s great.
Yes – see http://codex.wordpress.org/Child_Themes
Bob
Version 4.17 is updated with the Scroll Action. If you can, please rate the plugin and add a review — if you like my support and the plugin.
Thanks,
Bob
Hi Bob
I could not get the menu to work.
I added the code to the child theme.
You said
In the PHP (Prefix or Suffix – your choice)… use this code:
wp_nav_menu(array('menu'=>'wptopbar-menu' ));I am not sure what I did wrong and did not understand the Prefix or Suffix bit.
When I added the php code under the PHP option in your plugin the top bar disappeared.
I did some more testing and it looks like it partially works only if you have the TopBar in the footer position.
The reason? They way that WordPress creates the Menu, it breaks how I inject the TopBar into the HTML stream (using the JavaScript function –
prepend()). WordPress includes characters that cannot be used in theprepend()function.Also, the prefix/suffix are the internal variable names I used. I should have written “before” and “after” PHP.
OK — so how to fix this? I have a partial solution:
Use this code in the “After” section instead of the code I gave you before.
$defaults = array( 'menu' => 'wptopbar-menu', 'echo' => 0 ); $menu = wp_nav_menu( $defaults); echo preg_replace("/\r\n|\r|\n/",'',$menu);HOWEVER, for some reason, the HTML causes the menus to get generated after the TopBar. I’ve looked at the generated HTML — and I cannot find a reason why it is doing that. Maybe someone with more advanced CSS skills can help solve this one!
Here is the generated HTML:
<div id="topbar1" style="top: 40; padding:0; margin:0; width: 100%; z-index: 99999;"><p id="wptbheadline1" style="....">Get your own TopBar <a style="color:#c00000; " href="http://wordpress.org/extend/plugins/wp-topbar/" target="_blank">from the WordPress plugin repository</a><div class="menu-topbarmenu-container"><ul id="menu-topbarmenu" class="menu"><li id="menu-item-435" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-435"><a href="http://null.org">null</a></li><li id="menu-item-436" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-436"><a href="http://null.com">null</a></li></ul></div></p></div>Bob
Ok – -found out how to fix it.
You need to edit wp-topbar.php
Changes lines 421/459 from “<p>”/”</p>” to “<div>”/”</div>”.
(I’ll change this in the next release.)
You’ll need to add styling to your menu via CSS to make it pretty. You can use this to set your classes:
$defaults = array( 'menu' => 'wptopbar-menu', 'menu_class' => 'wptb-menu-class', 'container_class' => 'wptb-container-class', 'echo' => 0 ); $menu = wp_nav_menu( $defaults); echo preg_replace("/\r\n|\r|\n/",'',$menu);Then style using
.wptb-menu-classor.wptb-container-class(whichever you prefer.)Hi Bob Thanks for the update. I will try it 😉
The topic ‘Additional Options: Add WP menu, Only Show on scroll’ is closed to new replies.