我已经为我的自定义帖子类型注册了自定义分类法:
$labels = array(
...labels here...
);
$args = array(
'label' => __('Categories', $this->text_domain),
'labels' => $labels,
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_admin_column' => true,
'hierarchical' => true,
'query_var' => true,
'rewrite' => array('slug' => 'virtual-product-category'),
);
register_taxonomy('virtual_product_cat', array('virtual_product'), $args);
工作如预期-我可以为我的自定义帖子选择自定义类别。
然后我将其添加到自定义菜单中:
add_submenu_page(
'virtual',
__('Virtual Product Categories', $this->text_domain),
__('Categories', $this->text_domain),
'edit_products',
'edit-tags.php?post_type=virtual_product&taxonomy=virtual_product_cat'
);
它显示:
当我点击它(“类别”链接)时,分类法编辑页面加载良好,但是,父菜单显示为折叠,子菜单(“类别”)不突出显示:
另一方面,定制的post类型(linke“virtualproducts”)工作正常(见第一张图)。
我可以做一些破解/解决方法,使用JS/CSS使其突出显示,但我认为我缺少了一些东西。。
那么,如何使自定义菜单下的自定义分类菜单链接正常工作?
谢谢
您可以使用这个作为模板,或者像我一样使用这个分类生成器。
// Register Custom Taxonomy
function Stack_Overflow() {
$labels = array(
'name' => _x( 'Question', 'Taxonomy General Name', 'stack_overflow' ),
'singular_name' => _x( 'Question', 'Taxonomy Singular Name', 'stack_overflow' ),
'menu_name' => __( 'Stack Overflow', 'stack_overflow' ),
'all_items' => __( 'All Questions', 'stack_overflow' ),
'parent_item' => __( 'Language', 'stack_overflow' ),
'parent_item_colon' => __( 'Framework', 'stack_overflow' ),
'new_item_name' => __( 'New Question', 'stack_overflow' ),
'add_new_item' => __( 'Ask Question', 'stack_overflow' ),
'edit_item' => __( 'Edit Question', 'stack_overflow' ),
'update_item' => __( 'Edit Question', 'stack_overflow' ),
'separate_items_with_commas' => __( '', 'stack_overflow' ),
'search_items' => __( 'Search Questions', 'stack_overflow' ),
'add_or_remove_items' => __( 'Add or Remove Questions', 'stack_overflow' ),
'choose_from_most_used' => __( 'Choose from the most popular languages', 'stack_overflow' ),
);
$rewrite = array(
'slug' => 'questions',
'with_front' => true,
'hierarchical' => true,
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => 'question',
'rewrite' => $rewrite,
'update_count_callback' => 'display_edit_count',
);
register_taxonomy( 'stakoverflow', 'page', $args );
}
// Hook into the 'init' action
add_action( 'init', 'Stack Overflow', 0 );
我也在寻找同样的东西,但我不想使用自定义Post类型作为主菜单。
我最终在WP上找到了这个链接。组织支持论坛http://wordpress.org/support/topic/moving-taxonomy-ui-to-another-main-menu
代码概述如下。
function recipe_tax_menu_correction($parent_file) {
global $current_screen;
$taxonomy = $current_screen->taxonomy;
if ($taxonomy == 'ingredient' || $taxonomy == 'cuisine' || $taxonomy == 'course' || $taxonomy == 'skill_level')
$parent_file = 'recipe_box_options';
return $parent_file;
}
add_action('parent_file', 'recipe_tax_menu_correction');
好吧,对于所有遇到同样问题的人来说...
你正在做的是:
add\u menu\u页面创建自定义菜单
改为这样做:
'show_in_menu'
参数-这将为您创建一个菜单。您可以通过在同一个args数组下设置'menu_position'
来控制它出现的位置。 add_submenu_page
时,使用'edit.php?post_type=%%post_type_name%%'
作为父段(第一个参数)。简单地-不要做其他方式:)
多亏了奥伯克·克罗宁和臭臭,他们试图帮忙。谢谢你。
我找到了很多解决方案,但我的情况完全不同。 现在我的问题是,我正在开发一个插件,在插件中我制作了自定义帖子类型和自定义分类法,首先它的slug是不同的,现在我希望post类型slug和分类法slug是相同的,我也成功地实现了这一点,但有一个问题是,我的类别链接没有显示在管理菜单中,因为当我注册分类法时,我将object_type设置为slug,这在post类型slug和分类法slug中是相同的,但
我试图显示一个管理菜单项下的自定义分类法,这只是一个页面,即http://example.com/wp-admin/admin.php?page=bla. 根据register\u分类法下的WordPress Dev.页面的,它说: “某些字符串”-如果是现有的顶级页面,如“工具”。php“或”编辑。php?post_type=page',post类型将作为该页面的子菜单放置。 这是否意味着分类法
我不知道为什么自定义文章类型的自定义分类不显示在管理列中(它消失了)。 以下是始终有效的代码: 如下所述: https://codex.wordpress.org/Function_Reference/register_taxonomy 第二个参数设置为null,因为在使用register\u post\u type()时,我将分类法与自定义post类型相关联 我不知道为什么代码停止工作了。我从3
我在WordPress文件,但当我想添加新文章或编辑新文章时,在“管理”菜单的右侧找不到自定义分类法元框 我的代码用于自定义分类法: 但我找不到我在截图中标记的位置: 我忘记或错过了什么吗?
我已经搜索了又搜索,除了我称之为“hack方法”的方法之外,找不到其他方法将自定义分类添加到自定义管理菜单中。 然后我注册我的帖子类型并确保它们使用 这可以工作,自定义帖子类型显示在我的自定义菜单中。 但是自定义分类法不接受同一属性的字符串,只接受true或false。 因此,要添加它,您必须创建一个子菜单页 这是一种“黑客”方式。 还有别的办法吗?如果不修改WordPress核心,我可以覆盖re
获取频道自定义菜单 删除频道自定义菜单 设置频道自定义菜单