wp_nav_menu too simplistic?

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

wp_nav_menu too simplistic?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

Anybody figured out how to use the new menus system to create a
dropdown menu? Generally I use this code in my top menus:

wp_list_pages('title_li=&depth=2&sort_column=menu_order');

Which creates a nested LI-UL-LI type of system out of top-level pages
and their children. With this, I can then easily use CSS hovers to
make it into a dropdown menu. You can do something similar with
wp_list_categories.

But the new menu system doesn't seem to have any way to do this sort
of thing. Or, at least, I haven't figured out a way yet. I thought it
was going to be more like widgets instead, where you have different
types of things you can drag onto a menu.

Basically, the new menus system just looks way too simplistic to me .
If the new menu system isn't as capable as the standard ways of doing
things, then why would a theme author ever implement it?

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by John O'Nolan :: Rate this Message:

| View Threaded | Show Only this Message

As far as I know this functionality has existed from the very start
http://www.woothemes.com/2010/01/the-awesome-custom-woo-navigation/

Your email was a little dramatic

John





On 6 Apr 2010, at 16:42, Otto wrote:

> Anybody figured out how to use the new menus system to create a
> dropdown menu? Generally I use this code in my top menus:
>
> wp_list_pages('title_li=&depth=2&sort_column=menu_order');
>
> Which creates a nested LI-UL-LI type of system out of top-level pages
> and their children. With this, I can then easily use CSS hovers to
> make it into a dropdown menu. You can do something similar with
> wp_list_categories.
>
> But the new menu system doesn't seem to have any way to do this sort
> of thing. Or, at least, I haven't figured out a way yet. I thought it
> was going to be more like widgets instead, where you have different
> types of things you can drag onto a menu.
>
> Basically, the new menus system just looks way too simplistic to me .
> If the new menu system isn't as capable as the standard ways of doing
> things, then why would a theme author ever implement it?
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers

_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 6, 2010 at 10:59 AM, John O'Nolan <john.wp@...> wrote:
> As far as I know this functionality has existed from the very start
> http://www.woothemes.com/2010/01/the-awesome-custom-woo-navigation/

Umm... That functionality I described isn't there at all *right now*,
as far as I can tell. That link shows how to add static links to
pages, which is not what I was describing.

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by John O'Nolan :: Rate this Message:

| View Threaded | Show Only this Message

"Which creates a nested LI-UL-LI type of system"

Yes it does that, based on whatever you put into the menu admin  
interface.


"of top-level pages and their children"

No it doesn't do that, why would it? If you wanted that, then you'd  
use wp_list_pages. It wouldn't make any sense to try and translate  
that into some sort of dynamic menu system... 99% of users would have  
no use for it as their menus aren't even big enough to worry about  
needing a dynamic query.


"If the new menu system isn't as capable as the standard ways of doing  
things, then why would a theme author ever implement it?"

Because it's much MORE capable. I don't need to explain to my users  
"create some categories and some pages and they'll show up in your  
nav, then go to this other page and select the Page and Category ID's  
to exclude from this menu, you can find out the ID by going to  
the...... hey, what are you doing? Wake up! What do you mean you want  
them in a different order, no we can't do that. Oh you want a custom  
link in your nav? Too bad."

Instead I'll say "Go to the menus section, and create your navigation  
menu with whatever pages, categories or links that you want and drag
+drop to arrange them."


John







On 6 Apr 2010, at 17:27, Otto wrote:

> On Tue, Apr 6, 2010 at 10:59 AM, John O'Nolan <john.wp@...>  
> wrote:
>> As far as I know this functionality has existed from the very start
>> http://www.woothemes.com/2010/01/the-awesome-custom-woo-navigation/
>
> Umm... That functionality I described isn't there at all *right now*,
> as far as I can tell. That link shows how to add static links to
> pages, which is not what I was describing.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers

_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 6, 2010 at 11:42 AM, John O'Nolan <john.wp@...> wrote:
> Because it's much MORE capable.

So, it's unable to create a dynamic menu of my pages, and that's
somehow "more" to you?

Look, I get drag and drop. Yay, lovely, fine. What I want to know is
why is it not more like the widgets mechanism, where I can, say, drag
and drop a "Pages" widget there and then configure it to show one of
my pages and all of that pages children underneath it? Seems like a
rather obvious thing to do, to me.

As it stands, every time I add a page, I'd have to go muck about with
my menu and adding that page to it. That seems like a major step
backwards to me.

Yay for reordering, yay for widgetization, but boo to poor selection
of possible menu items. This new menu system seems little better than
manually editing the HTML to me. Every item in it is a static link,
basically. You have to manually define every single one, there's no
intelligence here at all.

Is it even possible to expand the types of menu items with plugins?
I've only just started diving into this thing, but if there's some
kind of plugin that can add "smart" menu items, then maybe we'd be
getting somewhere.

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Nathan Rice :: Rate this Message:

| View Threaded | Show Only this Message

Otto,
So (if I'm understanding you right), you would wish for the ability to
perhaps select a parent page and, say, 4 of its subpages, click "add" and
the hierarchy is maintained when they are added to the menu? (same for
categories)

Then, you could move the pages around, reorder, rearrange, etc.

+1 for that. I've always wondered a bit why the hierarchy isn't maintained
when adding groups of pages/cats to a menu.

------------------
Nathan Rice
WordPress and Web Development
www.nathanrice.net | twitter.com/nathanrice


On Tue, Apr 6, 2010 at 1:24 PM, Otto <otto@...> wrote:

> On Tue, Apr 6, 2010 at 11:42 AM, John O'Nolan <john.wp@...> wrote:
> > Because it's much MORE capable.
>
> So, it's unable to create a dynamic menu of my pages, and that's
> somehow "more" to you?
>
> Look, I get drag and drop. Yay, lovely, fine. What I want to know is
> why is it not more like the widgets mechanism, where I can, say, drag
> and drop a "Pages" widget there and then configure it to show one of
> my pages and all of that pages children underneath it? Seems like a
> rather obvious thing to do, to me.
>
> As it stands, every time I add a page, I'd have to go muck about with
> my menu and adding that page to it. That seems like a major step
> backwards to me.
>
> Yay for reordering, yay for widgetization, but boo to poor selection
> of possible menu items. This new menu system seems little better than
> manually editing the HTML to me. Every item in it is a static link,
> basically. You have to manually define every single one, there's no
> intelligence here at all.
>
> Is it even possible to expand the types of menu items with plugins?
> I've only just started diving into this thing, but if there's some
> kind of plugin that can add "smart" menu items, then maybe we'd be
> getting somewhere.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by John O'Nolan :: Rate this Message:

| View Threaded | Show Only this Message


> On Tue, Apr 6, 2010 at 11:42 AM, John O'Nolan <john.wp@...>  
> wrote:
>> Because it's much MORE capable.
>
> So, it's unable to create a dynamic menu of my pages, and that's
> somehow "more" to you?
Yes, I'm suggesting that less is more. It's a strange concept, I know.

>
> Look, I get drag and drop. Yay, lovely, fine. What I want to know is
> why is it not more like the widgets mechanism, where I can, say, drag
> and drop a "Pages" widget there and then configure it to show one of
> my pages and all of that pages children underneath it? Seems like a
> rather obvious thing to do, to me.
>
> As it stands, every time I add a page, I'd have to go muck about with
> my menu and adding that page to it. That seems like a major step
> backwards to me.
>
> Yay for reordering, yay for widgetization, but boo to poor selection
> of possible menu items. This new menu system seems little better than
> manually editing the HTML to me. Every item in it is a static link,
> basically. You have to manually define every single one, there's no
> intelligence here at all.
Most people populate a navigation menu once when they build a site and  
about once a year after that. It's really not the huge deal you're  
making it out to be.

>
> Is it even possible to expand the types of menu items with plugins?
> I've only just started diving into this thing, but if there's some
> kind of plugin that can add "smart" menu items, then maybe we'd be
> getting somewhere.
No one is forcing you to use the new menus. If you prefer  
wp_list_pages then use that instead. Better yet, if you hate the way  
the current menus work so much, why not write some code that you think  
is an improvement?

>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers

_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 6, 2010 at 12:33 PM, Nathan Rice <ncrice@...> wrote:

> Otto,
> So (if I'm understanding you right), you would wish for the ability to
> perhaps select a parent page and, say, 4 of its subpages, click "add" and
> the hierarchy is maintained when they are added to the menu? (same for
> categories)
>
> Then, you could move the pages around, reorder, rearrange, etc.
>
> +1 for that. I've always wondered a bit why the hierarchy isn't maintained
> when adding groups of pages/cats to a menu.

What I would wish for is the ability to pick, say, one Page. And then
have all its subpages added under it and hierarchy maintained as well.
AND to have this done dynamically, so that I don't have to screw
around with the menu every time I add a Page.

Adding a Page right now causes it to auto-appear in my menus. I don't
want that to be some kind of silly manual process.

Looking closer at this menu system, it appears to only be storing
names and URLs. There's no hint of anything dynamically created here
at all, via callback or anything else. If I change the URL to one of
my Pages, for example, my menu is now invalid and broken.

So far, I'm very much -1 against it. It should be a whole lot smarter than this.

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 6, 2010 at 12:35 PM, John O'Nolan <john.wp@...> wrote:
> Yes, I'm suggesting that less is more. It's a strange concept, I know.

Less would be more, if less was expandable. That's the general
WordPress way, to create frameworks and let other people fill in those
gaps.

> Most people populate a navigation menu once when they build a site and about
> once a year after that. It's really not the huge deal you're making it out
> to be.

It's a step backwards in functionality, and yes, I think it is a big
deal. Especially since it seems extremely limited in scope and
non-expandable to boot.

> Better yet, if you hate the way the current menus work so
> much, why not write some code that you think is an improvement?

That's exactly what I have been trying to do, and that is why I was
ASKING these questions. I'm pretty sure I said 'Is it even possible to
expand the types of menu items with plugins?" If you don't know these
answers, then why are you responding at all?

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by John O'Nolan :: Rate this Message:

| View Threaded | Show Only this Message



>> Better yet, if you hate the way the current menus work so
>> much, why not write some code that you think is an improvement?
>
> That's exactly what I have been trying to do, and that is why I was
> ASKING these questions. I'm pretty sure I said 'Is it even possible to
> expand the types of menu items with plugins?" If you don't know these
> answers, then why are you responding at all?

Really? At what point did you say "I'd love to improve this by writing  
in some extra functionality" ? As far as I can tell, all you're  
interested in doing is complaining.

I attempted several times to answer your questions, but you're just  
looking for a petty little fight rather than to do anything  
constructive - which I'm really not at all interested in I'm afraid.  
So I'll leave it at that.

Cheers

John
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Nathan Rice :: Rate this Message:

| View Threaded | Show Only this Message

No disrespect, but complaints aren't all bad. At some point, someone
complained that WP didn't have a decent menu manager.

------------------
Nathan Rice
WordPress and Web Development
www.nathanrice.net | twitter.com/nathanrice


On Tue, Apr 6, 2010 at 2:30 PM, John O'Nolan <john.wp@...> wrote:

>
>
>  Better yet, if you hate the way the current menus work so
>>> much, why not write some code that you think is an improvement?
>>>
>>
>> That's exactly what I have been trying to do, and that is why I was
>> ASKING these questions. I'm pretty sure I said 'Is it even possible to
>> expand the types of menu items with plugins?" If you don't know these
>> answers, then why are you responding at all?
>>
>
> Really? At what point did you say "I'd love to improve this by writing in
> some extra functionality" ? As far as I can tell, all you're interested in
> doing is complaining.
>
> I attempted several times to answer your questions, but you're just looking
> for a petty little fight rather than to do anything constructive - which I'm
> really not at all interested in I'm afraid. So I'll leave it at that.
>
> Cheers
>
> John
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by John Bloch :: Rate this Message:

| View Threaded | Show Only this Message

Otto,

To answer your question, it's entirely possible to do all that with a
plugin. That doesn't mean it wouldn't be a LOT of work, though.

John P. Bloch


On Tue, Apr 6, 2010 at 2:33 PM, Nathan Rice <ncrice@...> wrote:

> No disrespect, but complaints aren't all bad. At some point, someone
> complained that WP didn't have a decent menu manager.
>
> ------------------
> Nathan Rice
> WordPress and Web Development
> www.nathanrice.net | twitter.com/nathanrice
>
>
> On Tue, Apr 6, 2010 at 2:30 PM, John O'Nolan <john.wp@...> wrote:
>
> >
> >
> >  Better yet, if you hate the way the current menus work so
> >>> much, why not write some code that you think is an improvement?
> >>>
> >>
> >> That's exactly what I have been trying to do, and that is why I was
> >> ASKING these questions. I'm pretty sure I said 'Is it even possible to
> >> expand the types of menu items with plugins?" If you don't know these
> >> answers, then why are you responding at all?
> >>
> >
> > Really? At what point did you say "I'd love to improve this by writing in
> > some extra functionality" ? As far as I can tell, all you're interested
> in
> > doing is complaining.
> >
> > I attempted several times to answer your questions, but you're just
> looking
> > for a petty little fight rather than to do anything constructive - which
> I'm
> > really not at all interested in I'm afraid. So I'll leave it at that.
> >
> > Cheers
> >
> > John
> >
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers@...
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 6, 2010 at 1:41 PM, John Bloch <jbloch@...> wrote:
> Otto,
>
> To answer your question, it's entirely possible to do all that with a
> plugin. That doesn't mean it wouldn't be a LOT of work, though.
>
> John P. Bloch

Actually, no, I don't think it is. I spent the better part of the last
couple hours reading the code and I can't find any way to do it.

The Woo code basically makes a fundamental assumption that a menu item
is a static URL. There's no way to make it call PHP code, there's no
way to make it have a callback, there's basically no way to do
anything except make it a static URL.

Side note, this makes the new menu system exceedingly fragile. If you
change the URL of a Page or change the category name or anything else
along those lines, your menus are now broken.

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 6, 2010 at 1:43 PM, Otto <otto@...> wrote:
> Side note, this makes the new menu system exceedingly fragile. If you
> change the URL of a Page or change the category name or anything else
> along those lines, your menus are now broken.

Scratch that, I was mistaken there. There's code in
wp_setup_nav_menu_item that takes care of this specific case.

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by John Bloch :: Rate this Message:

| View Threaded | Show Only this Message

Even without that pre-built functionality, there are still the normal hooks
that you have when updating a page. Nobody said it's easy to code such a
plugin; I just said that it was possible.

Something that would greatly simplify the process is using a
post_meta value in each page's entry containing the corresponding menu item
ID(s). That way, when you update the page, you can check the values that
should be the same to see if they have changed, and if so, update them
accordingly. That would be things like hierarchy or static link, etc.

John P. Bloch


On Tue, Apr 6, 2010 at 2:46 PM, Otto <otto@...> wrote:

> On Tue, Apr 6, 2010 at 1:43 PM, Otto <otto@...> wrote:
> > Side note, this makes the new menu system exceedingly fragile. If you
> > change the URL of a Page or change the category name or anything else
> > along those lines, your menus are now broken.
>
> Scratch that, I was mistaken there. There's code in
> wp_setup_nav_menu_item that takes care of this specific case.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 6, 2010 at 2:16 PM, John Bloch <jbloch@...> wrote:
> Even without that pre-built functionality, there are still the normal hooks
> that you have when updating a page. Nobody said it's easy to code such a
> plugin; I just said that it was possible.

Yuck. Okay, so I consider hacky ways of doing things to be invalid.
Therefore, it is not possible. :)

There's no action hooks or filters or anything in the menu generation
system. Basically, the wp_setup_nav_menu_item builds the url and such,
then that gets passed to wp_get_nav_menu_item which builds the link,
and then it gets shoved into the output.

Short of hideous regexp and filtering that whole menu and such,
there's no way to insert stuff into the menu dynamically. All you can
do is recognize changes and then modify the menu (and probably break
it in the process, the ordering system is fragile as well).

A better solution would be to make the menu system not all so focused
on static links and use something more like widgets, which get called
to build their link (and which could then be static, if desired). Then
it'd be more configurable and more expandable.  Plus we wouldn't need
all this Woo code for Ajax and such, since a widget system already
exists and is in the core.

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by John Bloch :: Rate this Message:

| View Threaded | Show Only this Message

Or you could declare your own Walker class, copying the exact nav menu
walker and just adding your own filters onto whatever you want, then just
use the new class name as the 'walker' attribute when you call the menu.

Also, there are filters and actions all over the menus. For example,
nav_menu_css_class is a hook that lets you sort through an array of classes
applied to each and every menu item and add or remove classes. That's just
one of at least a dozen that I saw while taking a cursory look through the
menu functions.

John P. Bloch


On Tue, Apr 6, 2010 at 3:27 PM, Otto <otto@...> wrote:

> On Tue, Apr 6, 2010 at 2:16 PM, John Bloch <jbloch@...>
> wrote:
> > Even without that pre-built functionality, there are still the normal
> hooks
> > that you have when updating a page. Nobody said it's easy to code such a
> > plugin; I just said that it was possible.
>
> Yuck. Okay, so I consider hacky ways of doing things to be invalid.
> Therefore, it is not possible. :)
>
> There's no action hooks or filters or anything in the menu generation
> system. Basically, the wp_setup_nav_menu_item builds the url and such,
> then that gets passed to wp_get_nav_menu_item which builds the link,
> and then it gets shoved into the output.
>
> Short of hideous regexp and filtering that whole menu and such,
> there's no way to insert stuff into the menu dynamically. All you can
> do is recognize changes and then modify the menu (and probably break
> it in the process, the ordering system is fragile as well).
>
> A better solution would be to make the menu system not all so focused
> on static links and use something more like widgets, which get called
> to build their link (and which could then be static, if desired). Then
> it'd be more configurable and more expandable.  Plus we wouldn't need
> all this Woo code for Ajax and such, since a widget system already
> exists and is in the core.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by John Bloch :: Rate this Message:

| View Threaded | Show Only this Message

This custom walker class will give you a filter to directly modify the
url of individual menu items. Put this into your theme's function file
and, when you call the menu, add "walker=Custom_Walker_Nav_Menu" to
the function's arguments.

class Custom_Walker_Nav_Menu extends Walker {
        /**
         * @see Walker::$tree_type
         * @since 3.0.0
         * @var string
         */
        var $tree_type = array( 'post_type', 'taxonomy', 'custom' );

        /**
         * @see Walker::$db_fields
         * @since 3.0.0
         * @todo Decouple this.
         * @var array
         */
        var $db_fields = array( 'parent' => 'post_parent', 'id' => 'object_id' );

        /**
         * @see Walker::start_lvl()
         * @since 3.0.0
         *
         * @param string $output Passed by reference. Used to append
additional content.
         * @param int $depth Depth of page. Used for padding.
         */
        function start_lvl(&$output, $depth) {
                $indent = str_repeat("\t", $depth);
                $output .= "\n$indent<ul class=\"sub-menu\">\n";
        }

        /**
         * @see Walker::end_lvl()
         * @since 3.0.0
         *
         * @param string $output Passed by reference. Used to append
additional content.
         * @param int $depth Depth of page. Used for padding.
         */
        function end_lvl(&$output, $depth) {
                $indent = str_repeat("\t", $depth);
                $output .= "$indent</ul>\n";
        }

        /**
         * @see Walker::start_el()
         * @since 3.0.0
         *
         * @param string $output Passed by reference. Used to append
additional content.
         * @param object $item Menu item data object.
         * @param int $depth Depth of menu item. Used for padding.
         * @param int $current_page Menu item ID.
         * @param array $args
         */
        function start_el(&$output, $item, $depth, $args) {
                $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

                $classes = $value = '';
                if ( 'frontend' == $args->context ) {
                        global $wp_query;

                        $classes = array( 'menu-item', 'menu-item-type-'. $item->type,
$item->classes );

                        if ( 'custom' != $item->object )
                                $classes[] = 'menu-item-object-'. $item->object;

                        if ( $item->object_id == $wp_query->get_queried_object_id() )
                                $classes[] = 'current-menu-item';

                        // @todo add classes for parent/child relationships

                        $classes = join( ' ', apply_filters( 'nav_menu_css_class',
array_filter( $classes ), $item ) );
                        $classes = ' class="' . esc_attr( $classes ) . '"';
                } else {
                        $value = ' value="' . $item->ID . '"';
                }


$item->url = apply_filters( 'my_custom_nav_menu_links_filter',
(string)$item->url );

                $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value
. $classes .'>' . wp_get_nav_menu_item( $item, $args->context, $args
);
        }

        /**
         * @see Walker::end_el()
         * @since 3.0.0
         *
         * @param string $output Passed by reference. Used to append
additional content.
         * @param object $item Page data object. Not used.
         * @param int $depth Depth of page. Not Used.
         */
        function end_el(&$output, $item, $depth) {
                $output .= "</li>\n";
        }

}


John P. Bloch


On Tue, Apr 6, 2010 at 3:58 PM, John Bloch <jbloch@...>wrote:

> Or you could declare your own Walker class, copying the exact nav menu
> walker and just adding your own filters onto whatever you want, then just
> use the new class name as the 'walker' attribute when you call the menu.
>
> Also, there are filters and actions all over the menus. For example,
> nav_menu_css_class is a hook that lets you sort through an array of classes
> applied to each and every menu item and add or remove classes. That's just
> one of at least a dozen that I saw while taking a cursory look through the
> menu functions.
>
> John P. Bloch
>
>
> On Tue, Apr 6, 2010 at 3:27 PM, Otto <otto@...> wrote:
>
>> On Tue, Apr 6, 2010 at 2:16 PM, John Bloch <jbloch@...>
>> wrote:
>> > Even without that pre-built functionality, there are still the normal
>> hooks
>> > that you have when updating a page. Nobody said it's easy to code such a
>> > plugin; I just said that it was possible.
>>
>> Yuck. Okay, so I consider hacky ways of doing things to be invalid.
>> Therefore, it is not possible. :)
>>
>> There's no action hooks or filters or anything in the menu generation
>> system. Basically, the wp_setup_nav_menu_item builds the url and such,
>> then that gets passed to wp_get_nav_menu_item which builds the link,
>> and then it gets shoved into the output.
>>
>> Short of hideous regexp and filtering that whole menu and such,
>> there's no way to insert stuff into the menu dynamically. All you can
>> do is recognize changes and then modify the menu (and probably break
>> it in the process, the ordering system is fragile as well).
>>
>> A better solution would be to make the menu system not all so focused
>> on static links and use something more like widgets, which get called
>> to build their link (and which could then be static, if desired). Then
>> it'd be more configurable and more expandable.  Plus we wouldn't need
>> all this Woo code for Ajax and such, since a widget system already
>> exists and is in the core.
>>
>> -Otto
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers@...
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 6, 2010 at 3:13 PM, John Bloch <jbloch@...> wrote:
> This custom walker class will give you a filter to directly modify the
> url of individual menu items. Put this into your theme's function file
> and, when you call the menu, add "walker=Custom_Walker_Nav_Menu" to
> the function's arguments.

So what you're saying is that you can't make a plugin do it, it has to
be a theme that does it, by modifying the call to wp_nav_menu.

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: wp_nav_menu too simplistic?

by Otto-19 :: Rate this Message:

| View Threaded | Show Only this Message

On Tue, Apr 6, 2010 at 3:17 PM, Otto <otto@...> wrote:
> On Tue, Apr 6, 2010 at 3:13 PM, John Bloch <jbloch@...> wrote:
>> This custom walker class will give you a filter to directly modify the
>> url of individual menu items. Put this into your theme's function file
>> and, when you call the menu, add "walker=Custom_Walker_Nav_Menu" to
>> the function's arguments.
>
> So what you're saying is that you can't make a plugin do it, it has to
> be a theme that does it, by modifying the call to wp_nav_menu.

Ahh, no, a plugin can do it. There's a filter you can use to force the
walker, "wp_nav_menu_args".

Rather a long way to go though. And it doesn't allow for multiple
plugins creating different types of menu items, since only one walker
can be used.

BTW, in your example, it would actually make more sense for
Custom_Walker_Nav_Menu to extend Walker_Nav_Menu. Then you could
override just the start_el function, leaving the rest alone.

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers
< Prev | 1 - 2 | Next >