我制作了自定义帖子类型及其分类法。在主题选项中我更改了主页的slug,它的工作正常。但是当我重命名与页面slug相同的post类型slug时,它不起作用(我认为它是冲突的)。
但是当我用不同的名称重命名帖子类型slug时,它可以正常工作。
我想为页面,帖子类型和分类设置相同的slug。我怎么能这样做?
这是我的代码:
add_action('init', 'foo_articles');
function foo_articles() {
$foo_slug = 'foo_articles_post';
$foo_slug = get_option('foo_plugin_slug');
$labels = array(
'name' => __('Foo Posts', 'foo'),
'singular_name' => __('Foo Posts', 'foo'),
'all_items' => __('Articles', 'foo'),
'add_new' => __('New Article', 'foo'),
'add_new_item' => __('Add New Article', 'foo'),
'edit_item' => __('Edit Article', 'foo'),
'new_item' => __('New Article', 'foo'),
'view_item' => __('View Articles', 'foo'),
'search_items' => __('Search Articles', 'foo'),
'not_found' => __('Nothing found', 'foo'),
'not_found_in_trash' => __('Nothing found in Trash', 'foo')
'parent_item_colon' => ''
);
$foo_rewrite = array(
'slug' => $foo_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' => plugin_dir_url(__FILE__)).'images/icon-foo.png',
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 3,
'supports' => array('title','editor','thumbnail','comments'),
'rewrite' => $kbe_rewrite,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true
);
register_post_type( 'foo_articles_post' , $args );
}
add_action( 'init', 'foo_taxonomies', 0 );
// Article taxonamy
function foo_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => __( 'Foo Category', 'foo'),
'singular_name' => __( 'Foo Category', 'foo' ),
'search_items' => __( 'Search Foo Category', 'foo' ),
'all_items' => __( 'All Foo Categories', 'foo' ),
'parent_item' => __( 'Parent Foo Category', 'foo' ),
'parent_item_colon' => __( 'Parent Foo Category:', 'foo' ),
'edit_item' => __( 'Edit Foo Category', 'foo' ),
'update_item' => __( 'Update Foo Category', 'foo' ),
'add_new_item' => __( 'Add New Foo Category', 'foo' ),
'new_item_name' => __( 'New Foo Category Name', 'foo' ),
);
register_taxonomy( 'foo_taxonomy', array( 'foo_articles_post' ), array(
'hierarchical' => true,
"label" => 'Categories',
"singular_label" => "Foo Category",
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => $foo_slug )
));
}