Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm writing a plugin that displays a post/page list in the admin menu, as a submenu for each post type. Here's the code I've got far: http://pastebin.com/DmUGfzxN

The lists are showing and linking fine. However, I have a problem when I go to another menu, for example, Media, and go to edit a post (or image in this case). The current class that WordPress uses for the admin menu points to the wrong place, and opens the menu for Pages, highlighting the last submenu item.

I believe this is a related problem here: Current class on admin menu using add_submenu_page()

He solved it by adding the submenu page to a page slug, instead of a link like admin.php?=page.... Unfortunately, I want my submenus to be under Post, Page, etc., so I need to use edit.php and edit.php?post_type=....

If anyone has any ideas how to get around this quirk/bug, I'd appreciate it. Thank you.

share|improve this question
    
I got it solved. I listed the pages without using '<ul>' and '<li>', and just highlighted the current page with my own class. This avoids the default admin menu opening up on the wrong page. –  Lio Eters Oct 16 '13 at 5:36
    
Please add solution you came up with as an answer so that others can benefit from it and question doesn't haunt site as unanswered. Thank you. :) –  Rarst Oct 16 '13 at 8:08
add comment

1 Answer

Sure, here is how I rewrote it: http://pastebin.com/s3SG0SFE

Now it displays the submenu, and the current class doesn't affect it. Where I output the submenu, I changed the <ul> and <li> to <div>. I added a check to see if the menu item equals the current post being edited, and a little CSS in the admin_head to highlight the item. Please refer to the code paste above.

Next, I'll be looking into displaying child pages.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.