[wp-hackers] Hello, new developer with a question

Derek Hogue derek at amphibian.info
Sun Nov 18 16:39:50 GMT 2007


Andy,

Thanks, this is correct - Max emailed me off-list and provided a good  
test plug-in that helped me figure it out as well.

Since I have all of my child pages contained within my plug-in file as  
functions, the trick for getting the parent menu tab to link directly  
to the child page is to have them call the same function AND have the  
child-menu call the plug-in file (__FILE__) as its unique identifier.

If you use a different identifier, then you'll end up with two child  
pages with the exact same content - one named as per your top-level  
menu item, and one named as per the identical child item.

Here's the code that worked:

add_menu_page('Page title', 'Top-level menu title', 8, __FILE__,  
'my_magic_function');
add_submenu_page(__FILE__, 'Page title', 'Sub-menu title', 8,  
__FILE__, 'my_magic_function');

Thanks all,
Derek
--
http://amphibian.info



On Nov 17, 2007, at 7:58 PM, Andy Staines wrote:

> Well maybe I am doing something wrong - or, more likely - I have  
> misinterpreted the question, but this works for me
>
> function sf_admin_menu()
> {		
> 	add_menu_page('Simple Forum', 'Forum', 8, 'sf-adminforums.php');
> 	add_submenu_page('sf-adminforums.php', 'Manage Forum', 'Manage  
> Forums', 8, 'sf-adminforums.php');
> 	add_submenu_page('sf-adminforums.php', 'Manage Options', 'Manage  
> Options', 8, 'sf-adminoptions.php');
> }
>
> gives a different 'name' to the first menu item even if it runs the  
> same function.
> Am  I wrong?
> Andy
>
> On 10:32  PM |  Sat 17 Nov 07, at 10:32  PM |  17 Nov 07,  
> Viper007Bond wrote:
>
>> add_menu_page() does indeed add a child with the same name and it  
>> can be
>> rather annoying.
>>
>> I have a ticket open on the matter: http://trac.wordpress.org/ticket/5100
>>
>> Meanwhile, you could probably "fix" this by modifying the $submenu  
>> array.
>>
>> On 11/17/07, Callum Macdonald <lists.automattic.com at callum-macdonald.com 
>> >
>> wrote:
>>>
>>> Hey Derek,
>>>
>>> I'm pretty sure add_menu_page() doesn't add a child page. So you  
>>> could
>>> simply add a child page with the same page name and function, but a
>>> different title.
>>>
>>> However, if it does add a child page automatically, hook into the
>>> 'admin_menu' action and manually edit the $menu and $submenu  
>>> variables.
>>> You can see how they're structured in wp-admin/menu.php - it's  
>>> pretty
>>> straightforward.
>>>
>>> Cheers,
>>>
>>>
>>> Callum.
>>>
>>> Derek Hogue wrote:
>>>> Hey all,
>>>>
>>>> I'm just wrapping up work on my first WP plug-in, but there's one
>>>> thing I can't figure out.
>>>>
>>>> I'm adding a top-level menu (as I have 5 child pages), but what I'd
>>>> love to do is have the top-level menu name and the corresponding
>>>> sub-level menu name be different - in the same way that clicking on
>>>> "Write" takes you to the sub-menu called "Write Post".
>>>>
>>>> Is this doable within the plug-in API? Any ideas or help would be  
>>>> grand.
>>>>
>>>> I've searched around, but can't find any discussion of this  
>>>> online or
>>>> in the archives of this list.
>>>>
>>>> Thanks!
>>>> Derek
>>>> --
>>>> http://amphibian.info
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.com
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>>
>>>>
>>>
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>>
>>
>>
>> -- 
>> Viper007Bond | http://www.viper007bond.com/
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list