[英]Taxonomy link not showing in custom admin menu wordpress
我为此找到了许多解决方案,但是我的情况完全不同。
现在我的问题是,我正在使用一个插件,并且在插件中我进行自定义帖子类型和自定义分类法,首先它的子句是不同的,现在我希望帖子类型子句和分类法子句是相同的,并且我也成功实现了这一点,但是一个问题是我的类别链接没有显示在管理菜单中,因为当我注册分类法时,我将object_type设置为slug,这与帖子类型的slug和分类法标签相同,但是当我将对象类型更改为帖子类型名称类别菜单时,显示效果非常好。
这是我的代码
职务类型代码:
add_action('init', 'kbe_articles');
function kbe_articles() {
$labels = array(
'name' => __('Articles', 'kbe'),
'singular_name' => __('Articles', 'kbe'),
'all_items' => __('Articles', 'kbe'),
'add_new' => __('New Article', 'kbe'),
'add_new_item' => __('Add New Article', 'kbe'),
'edit_item' => __('Edit Article', 'kbe'),
'new_item' => __('New Article', 'kbe'),
'view_item' => __('View Articles', 'kbe'),
'search_items' => __('Search Articles', 'kbe'),
'not_found' => __('Nothing found', 'kbe'),
'not_found_in_trash' => __('Nothing found in Trash', 'kbe'),
'parent_item_colon' => ''
);
$kbe_rewrite = array(
'slug' => KBE_PLUGIN_SLUG,
'with_front' => false,
'pages' => true,
'feeds' => true,
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => WP_Articles.'images/icon-kbe.png',
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 3,
'supports' => array('title','editor','thumbnail','comments'),
'rewrite' => $kbe_rewrite,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true
);
register_post_type( 'kbe_articles' , $args );
flush_rewrite_rules();
}
分类代码:
add_action( 'init', 'kbe_taxonomies');
function kbe_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => __( 'Articles Category', 'kbe'),
'singular_name' => __( 'Articles Category', 'kbe' ),
'search_items' => __( 'Search Articles Category', 'kbe' ),
'all_items' => __( 'All Articles Categories', 'kbe' ),
'parent_item' => __( 'Parent Articles Category', 'kbe' ),
'parent_item_colon' => __( 'Parent Articles Category:', 'kbe' ),
'edit_item' => __( 'Edit Articles Category', 'kbe' ),
'update_item' => __( 'Update Articles Category', 'kbe' ),
'add_new_item' => __( 'Add New Articles Category', 'kbe' ),
'new_item_name' => __( 'New Articles Category Name', 'kbe' ),
);
register_taxonomy( 'kbe_taxonomy', array(KBE_PLUGIN_SLUG), array(
'hierarchical' => true,
"label" => 'Categories',
"singular_label" => "Articles Category",
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => true,
'rewrite' => array( 'slug' => KBE_PLUGIN_SLUG, 'with_front' => true ),
));
flush_rewrite_rules();
}
这是代码,因此我的帖子类型段和分类段段相同:
function taxonomy_slug_rewrite($wp_rewrite) {
$rules = array();
$taxonomies = get_taxonomies(array('_builtin' => false), 'objects');
$post_types = get_post_types(array('public' => true, '_builtin' => false), 'names');
foreach ($post_types as $post_type) {
$post_type_data = get_post_type_object( $post_type );
$post_type_slug = $post_type_data->rewrite['slug'];
foreach ($taxonomies as $taxonomy) {
if ($taxonomy->object_type[0] == $post_type_slug) {
$categories = get_categories(array('type' => $post_type_slug, 'taxonomy' => $taxonomy->name, 'hide_empty' => 0));
/* @var $category type */
foreach ($categories as $category) {
$rules[$post_type_slug . '/' . $category->slug . '/?$'] = 'index.php?' . $category->taxonomy . '=' . $category->slug;
}
}
}
}
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_filter( 'generate_rewrite_rules', 'taxonomy_slug_rewrite' );
这是我的菜单代码:
add_action('admin_menu', 'kbe_plugin_menu');
function kbe_plugin_menu() {
add_submenu_page('edit.php?post_type=kbe_articles', 'Order', 'Order', 'manage_options', 'kbe_order', 'wp_kbe_order');
add_submenu_page('edit.php?post_type=kbe_articles', 'Settings', 'Settings', 'manage_options', 'kbe_options', 'wp_kbe_options');
}
现在,当我更改register_taxonomy( 'kbe_taxonomy', array('kbe_articles'),
我的分类链接出现在管理员自定义菜单中,但是当我更改register_taxonomy( 'kbe_taxonomy', array(KBE_PLUGIN_SLUG),
菜单中的分类链接便register_taxonomy( 'kbe_taxonomy', array(KBE_PLUGIN_SLUG),
。
所以我该怎么做,我的分类链接出现在菜单中。 但不要换。
好的,这是答案。
我在条件上再添加一个子菜单
这是我的代码:
add_submenu_page('edit.php?post_type=foo_articles', 'Categories', 'Categories', 'manage_options', 'edit-tags.php?taxonomy=foo_taxonomy&post_type=foo_articles');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.