【发布时间】:2015-12-20 08:45:47
【问题描述】:
我通过此代码在管理面板中添加了一个页面菜单,它工作正常。
add_menu_page('Ads Dashboard', 'Ads Dashboard', 'administrator', 'adverts', 'advert_admin_options');
现在我需要在这个菜单下添加/注册帖子类型,但它不能正常工作。我的代码似乎有问题,这是我的全部代码:
function add_ads_post_type(){
register_post_type('ads', array(
'labels' => array(
'name' => __('Adverts', 'theme'),
'singular_name' => __('Adverts', 'theme'),
'menu_name' => __('Adverts', 'theme'),
'add_new' => __('Add Advert Item', 'theme'),
'add_new_item' => __('Add New Advert item', 'theme'),
'edit_item' => __('Edit Advert item', 'theme'),
'new_item' => __('New Advert item', 'theme'),
'view_item' => __('View Advert item', 'theme'),
'search_items' => __('Search Advert items', 'theme'),
'not_found' => __('No Advert found', 'theme'),
'not_found_in_trash' => __('No Advert items found in Trash', 'theme'),
),
'public' => TRUE,
'rewrite' => array('slug' => 'ads', 'with_front' => false),
'has_archive' => true,
'supports' => array('title', 'editor'),
'show_in_menu' => 'admin.php?page=adverts'
));
}
function advert_add_to_menu() {
if (is_admin()) {
add_menu_page('Ads Dashboard', 'Ads Dashboard', 'administrator', 'adverts', 'advert_admin_options');
add_submenu_page('adverts', 'Ads', 'Ads', 10, 'ads-list', 'add_ads_post_type' );
}
}
add_action('admin_menu', 'advert_add_to_menu');
【问题讨论】: