我创建了自定义帖子类型:书籍 并为此创建了重写规则:
$new_rules[ '([^/]+)$' ] = 'index.php?post_type=book&name=$matches[1]';
我的工作正常!书籍网址是: http://domain.com/bookname/
但是当我打开页面(默认页面posty类型)时,我收到404错误。
答案 0 :(得分:0)
在注册自定义帖子类型时将with_front
设置为false将从您的自定义帖子类型中移除slug,
'rewrite'=> array('slug'=>'book','with_front'=> false),
示例:使用rewrite
规则注册您的帖子类型时。请参阅register_post_type
add_action('init', 'codex_book_init');
function codex_book_init()
{
$labels = array(
'name' => _x('Books', 'post type general name', 'your-plugin-textdomain'),
'singular_name' => _x('Books', 'post type singular name', 'your-plugin-textdomain'),
'menu_name' => _x('Books', 'admin menu', 'your-plugin-textdomain'),
'name_admin_bar' => _x('Books', 'add new on admin bar', 'your-plugin-textdomain'),
'add_new' => _x('Add New', 'book', 'your-plugin-textdomain'),
'add_new_item' => __('Add New Books', 'your-plugin-textdomain'),
'new_item' => __('New Books', 'your-plugin-textdomain'),
'edit_item' => __('Edit Books', 'your-plugin-textdomain'),
'view_item' => __('View Books', 'your-plugin-textdomain'),
'all_items' => __('All Books', 'your-plugin-textdomain'),
'search_items' => __('Search Books', 'your-plugin-textdomain'),
'parent_item_colon' => __('Parent Books:', 'your-plugin-textdomain'),
'not_found' => __('No books found.', 'your-plugin-textdomain'),
'not_found_in_trash' => __('No books found in Trash.', 'your-plugin-textdomain')
);
$args = array(
'labels' => $labels,
'description' => __('Description.', 'your-plugin-textdomain'),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'book', 'with_front' => false),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments')
);
register_post_type('book', $args);
}
答案 1 :(得分:0)
要解决此问题,请在'with_front' => true
来电中使用register_post_type
参数启用网址基础,这样您的网址就会显示为domain.com/book/book_name