这里有一个非常简单的例子。其想法是在菜单配置中添加一个新的元框。add_meta_box 用于admin_head-nav-menus.php
页码:
class Custom_Nav {
function __construct() {
add_action( \'admin_head-nav-menus.php\', array( $this, \'add_nav_menu_meta_boxes\' ) );
}
public function add_nav_menu_meta_boxes() {
add_meta_box(
\'custom_links\',
__(\'Custom links\'),
array( $this, \'nav_menu_link\'),
\'nav-menus\',
\'side\',
\'low\'
);
}
public function nav_menu_link() {?>
<div id="posttype-custom-link" class="posttypediv">
<div id="tabs-panel-custom-link" class="tabs-panel tabs-panel-active">
<ul id ="custom-link-checklist" class="categorychecklist form-no-clear">
<li>
<label class="menu-item-title">
<input type="checkbox" class="menu-item-checkbox" name="menu-item[-1][menu-item-object-id]" value="-1"> <?php _e(\'Open entries\', \'text-doamin\'); ?>
</label>
<input type="hidden" class="menu-item-type" name="menu-item[-1][menu-item-type]" value="custom">
<input type="hidden" class="menu-item-title" name="menu-item[-1][menu-item-title]" value="<?php esc_attr_e(\'Open entries\', \'text-doamin\'); ?>">
<input type="hidden" class="menu-item-url" name="menu-item[-1][menu-item-url]" value="<?php echo esc_url( home_url(\'/open-entries\') ); ?>">
<input type="hidden" class="menu-item-classes" name="menu-item[-1][menu-item-classes]" value="custom-link">
</li>
</ul>
</div>
<p class="button-controls">
<span class="add-to-menu">
<input type="submit" class="button-secondary submit-add-to-menu right" value="Add to Menu" name="add-post-type-menu-item" id="submit-posttype-custom-link">
<span class="spinner"></span>
</span>
</p>
</div>
<?php }
}
$custom_nav = new Custom_Nav;