As part of a theme for a client, I want to be able to show a custom menu (defined via the admin) in a select box that automatically changes pages after changing the selection. Is there a plugin (or a handy code snippet) that will accomplish this?
|
Hi @Keith S.: WordPress' new menu system is both wondrous and infinitely frustrating, depending on what you are trying to do and what day of the week it happens to be. :) It's a great idea but far from mature so while it's a feature I applaud I'll be happier when v3.3 or v3.4 of WordPress rolls out and we get a lot more use-cases directly supported by the menu system's API. That said, not sure if there is an existing plugin to do what you are looking for, but how about the code you need to write you own plugin? Or you could just include it in your theme's What I'm providing is a fully self-contained example that you can save as
Here's what it look's like in action:
From the code below it should be easy to incorporate the
So you might wonder how it works? The
|
Holy crap! :)
Thanks for the lesson Mike. I think this will work just fine in my case. I don't know about wrapping it in a plugin at this point, but who knows...it may just end up there. If it does, you'll of course get credit... :)
Thanks for the title edit too...I was a bit frazzled when I wrote it, so I wasn't exactly thinking clearly... :) – Keith S. Aug 25 '10 at 14:39 |
|
Hmmm...apparently, something is wrong here...when I add the function to my functions.php file, I get the following:
Parse error: syntax error, unexpected ']', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /media/storage/swd/wp-content/themes/theme2/functions.php on line 55
line 55 is the $selector[] line in the foreach... – Keith S. Aug 25 '10 at 14:54 |
|
@Keith S.: Do you have any menu items for pages defined in your site yet? My code didn't protect against having zero menu items for pages (but I just updated the code to address that.) Did you make sure you used the correct menu name from your site? Did you ensure that the HTML; lines are NOT INDENTED?, i.e. that they are flush left with no spaces to the left of the HTML? Any chance your site is running on PHP4? (I don't know if this would matter, but it might.) In case you had a cut and paste error, here the code is where you can more easily copy it. gist.github.com/550217 – MikeSchinkel♦ Aug 25 '10 at 20:33 |
|
I had menu items set up, tried all sorts of indentation, but in the end, I would up doing this (which works fine...and for the record, I'm running php 5.3 on my dev server)... pastie.textmate.org/private/haynxduumjwxn8jdjtktq – Keith S. Aug 26 '10 at 3:18 |
|
@Keith S. - Look like you just dropped the filter on post_type=='page' which wasn't required by I did ironically to simplify things. But since it works for you without, go for it! – MikeSchinkel♦ Aug 26 '10 at 11:34 |


