Although I am very thankful to the wordpress core team that they have finally integrated native menu management capabilities I get frustrated with some key elements which I would like to change.
I need a way of showing pages which is hierarchical in the same way hierarchical categories are displayed instead of being in a list and I need a way of manually including links which can be added to a menu.
How can this be done?
Thanks in advance
UPDATED So, here are the two things I am trying to do. Currently if you go to the default wordpress “menu management” admin screen you can select to display the “pages” metabox on the left. The problem here is that when you click on the “view all” tab NONE of the pages are ordered correctly and they are not indented if applicable.
CURRENT DEFAULT LAYOUT:
DESIRED LAYOUT: (please note that I just indented them to show the parent relationship, the items should also be sorted based on their sort order).
Additionally, within this list (or if easier then within its own metabox) I need some way of hard coding links which should be presented in the form of a checkbox list so one can click elements and include them within the menu. The reason for this is that instead of having to manually add these elements using the “custom links” I would prefer to select them from a list.
Answer
I succeeded in this, but it is a mess. Basically, the walker should have the following parameters:
|
1 2 |
$this->db_fields['parent'] = 'post_parent';
$this->db_fields['id'] = 'ID'; |
But, to get that in place, you need to rip out the existing metabox callback, copy it, change one line so you get an extra filter, and place it back. Then you can pass your own walker that has these parameters set.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
add_filter( 'admin_head-nav-menus.php', 'wpse2770_admin_head_nav_menus' );
function wpse2770_admin_head_nav_menus()
{
// Hijack "Pages" meta box callback with one that has an extra filter for the walker class
$GLOBALS['wp_meta_boxes']['nav-menus']['side']['default']['add-page']['callback'] = 'wpse2770_wp_nav_menu_item_post_type_meta_box';
// Since Walker_Nav_Menu_Checklist is not always available, we create this class in this function (didn't even know that was possible...)
class WPSE2770_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu_Checklist
{
public function __construct()
{
$this->db_fields['parent'] = 'post_parent';
$this->db_fields['id'] = 'ID';
}
}
}
add_filter( 'wp_nav_menu_item_post_type_meta_box_walker', 'wpse2770_wp_nav_menu_item_post_type_meta_box_walker', 10, 3 );
function wpse2770_wp_nav_menu_item_post_type_meta_box_walker( $walker, $post_type, $context )
{
if ( 'page' == $post_type && 'view-all' == $context ) {
$walker = 'WPSE2770_Walker_Nav_Menu_Checklist';
}
return $walker;
}
function wpse2770_wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
global $_nav_menu_placeholder, $nav_menu_selected_id;
$post_type_name = $post_type['args']->name;
// paginate browsing for large numbers of post objects
$per_page = 50;
$pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) |




