Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Current Parent
#1
Hello everyone!
I just wanted to share my latest little contribution to the GetSimple CMS.
A plugin, that adds the "current" class to the parent navigation list item of the active page, so the entrys of both the current page and it's parent are highlighted.

More information can be found here.
Reply
#2
Thanks Manuel. Downloaded, tested and uploaded to a live site. Definitely an improvement in clarity. Appreciated. I like to use the child-menu plugin. It keeps everything small and simple.
Reply
#3
Thanks for your feedback. I am glad to hear, that is useful! :-)
Reply
#4
I imagine this is useless without a multi level plugin ?
I mean what would it provide for a parent in a a flat 1 d menu ?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
I use this in my templates to highlight the current page or parent in the (1-level) menu.
PHP Code:
<?php get_navigation(get_parent(false)==''?return_page_slug():get_parent(false)); ?>
Reply
#6
fyi new arg for get_nav in 3.3.
get_navigation($currentpage,$classPrefix = "")
* @param string $classPrefix Prefix that gets added to the parent and slug classnames

prevent issues if you have slugs names menu,error,footer who that might conflict with template css classes.
or if you want to modify the menu on certain pages or other prefix you want to add for selectors
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#7
(2014-02-08, 00:55:59)shawn_a Wrote: I imagine this is useless without a multi level plugin ?
I mean what would it provide for a parent in a a flat 1 d menu ?
Yes, as I explained I use it with Child Menu. May be of use with the Nested Menu plugin aswell, I guess.

(2014-02-08, 01:20:07)Carlos Wrote: I use this in my templates to highlight the current page or parent in the (1-level) menu.
PHP Code:
<?php get_navigation(get_parent(false)==''?return_page_slug():get_parent(false)); ?>
Thanks for the hint! That's similar to the way I wanted to accomplish it beforehand.
But I prefered to incorporate the functionality into a modular plugin, that is independend of the theme used, so it can be reused and easily installed by folks, who do not want to tinker with code at all.

@shawn_a: is there any way to call the get_navigation function without echoing? This way one could benefit from the cleaner looking code of Carlos' example, but still retain the advantages of a modular solution, like mine.
Reply
#8
You can build your own menu using your own function, but no.
you can use the filter "menuitems" to filter the html before it is returned.
or use output_buffering to grab the html from the function return.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#9
(2014-02-08, 02:42:21)shawn_a Wrote: You can build your own menu using your own function, but no.
you can use the filter "menuitems" to filter the html before it is returned.
or use output_buffering to grab the html from the function return.
Thanks for the reply!
Well building my own menu (like e.g. Nested Menu does) is what I tried to avoid, because that would rely on changing theme code aswell. I prefer to keep the plugin as modular and independent as possible.
Glad to hear, that using the "menuitems" filter is the proper procedure to achieve it, because that's what my plugin already does :-)
Reply
#10
@Timbow (and pretty much everybody else using Child Menu):
By the way, I have tweaked the theme I was using to integrate nicely with Child Menu.

http://get-simple.info/extend/theme/blac...ended/765/
Reply
#11
(2014-02-08, 01:50:42)mank319 Wrote: Thanks for the hint! That's similar to the way I wanted to accomplish it beforehand.
But I prefered to incorporate the functionality into a modular plugin, that is independend of the theme used, so it can be reused and easily installed by folks, who do not want to tinker with code at all.

Yes, yes, of course. It's a nice and handy plugin that makes this easier.

(2014-02-08, 02:48:45)mank319 Wrote: Well building my own menu (like e.g. Nested Menu does) is what I tried to avoid, because that would rely on changing theme code aswell. I prefer to keep the plugin as modular and independent as possible.

Using menuitems you could:
- return an empty string so that get_navigation echoes nothing, and echo your own menu.
or
- replace the whole string and replace it by your own menu so that get_navigation echoes it instead.
Reply
#12
Or use domloader and manipulate it as nodes, I have done this before but its a pita. You have to add a charset and then remove the html later, cause php requires the string to be proper html
PHP Code:
    $dom_document = new DOMDocument();
    
$dom_document->loadHTML($charsetstr $contents); 
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#13
it's working only for a two level menu..
how to integrate it for a multilevel menu.. no only two levels ?

active menu in the seccond level is activating a top menu as active (awesome)
but when i click and go to the page in the third level of menu.. this will only give me a active the button in the seccond level menu and third menu level.. the top level menu (1) is not active. how to fix it ?
user plugin: scroll to top
Reply
#14
(2014-02-14, 03:17:22)xxdex Wrote: it's working only for a two level menu..
how to integrate it for a multilevel menu.. no only two levels ?

active menu in the seccond level is activating a top menu as active (awesome)
but when i click and go to the page in the third level of menu.. this will only give me a active the button in the seccond level menu and third menu level.. the top level menu (1) is not active. how to fix it ?

The I18N plugin marks the navigation item of the current page with class=current and all parents with class=currentpath, see e.g. here.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#15
(2014-02-14, 03:17:22)xxdex Wrote: it's working only for a two level menu..
how to integrate it for a multilevel menu.. no only two levels ?

active menu in the seccond level is activating a top menu as active (awesome)
but when i click and go to the page in the third level of menu.. this will only give me a active the button in the seccond level menu and third menu level.. the top level menu (1) is not active. how to fix it ?

Hi and sorry for the delay :-)

Well for that purpose one would probably have to parse $menudata and generate the whole navigation menu, because I don't know if it is somehow possible to call get_parent for a page other than the active one. Right now I am just altering the generated HTML via the menuitems filter. I have chosen this approach, because I wanted the plugin to work with the default get_navigation function for those people who do not want to tinker with any code and don't feel like replacing something in their template.php file.

If you find a solution to implement this without having to write an own get_navigation function I would really appreciate your contribution! Otherwise I guess i18n really is better suited for more complex tasks like this.
Reply




Users browsing this thread: 1 Guest(s)