我有一个问题,我以前曾被问过,但没有一个答案解决了我的问题。这是我以前遇到的事情,但从未设法解决。
我有一个干净的Wordpress安装,在functions.php
文件中我创建了一个自定义帖子类型
register_nav_menu('main', 'Main navigation menu');
function add_custom_post_type() {
$labels = array(
'name' => _x('Books', 'post type general name'),
'singular_name' => _x('Book', 'post type singular name'),
'add_new' => _x('Add New', 'book'),
'add_new_item' => __('Add New Book'),
'edit_item' => __('Edit Book'),
'new_item' => __('New Book'),
'all_items' => __('All Books'),
'view_item' => __('View Book'),
'search_items' => __('Search Books'),
'not_found' => __('No books found'),
'not_found_in_trash' => __('No books found in Trash'),
'parent_item_colon' => '',
'menu_name' => __('Books')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type('book', $args);
}
我为这些人制作了archive-book.php
和single-book.php
模板文件,一切正常。当我去“http:// localhost / wordpress / book”时,我可以查看这些书
现在我想创建一个自定义分类法,所以我也在functions.php
中完成了这个:
add_action('init', 'add_custom_post_type');
function add_custom_taxonomy() {
register_taxonomy(
'rating',
'book',
array(
'label' => 'Rating',
'hierarchical' => true,
'show_ui' => true,
'query_var' => 'book',
'has_archive' => true,
'rewrite' => array(
'slug' => 'book/rating'
)
)
);
}
分类法显示在管理页面中,我可以添加新术语,并将它们添加到书籍中。但现在出现了问题。我想要概述所有书籍,比方说,评价“好”,我会去“http:// localhost / wordpress / book / rating / nice”。我创建了以下模板文件:taxonomy-rating-nice.php,taxonomy-rating.php和taxonomy.php。
但不知何故wordpress只显示index.php文件,并没有列出任何书籍。 我试过用以下方法来刷新重写规则:
add_action('init', 'custom_taxonomy_flush_rewrite');
function custom_taxonomy_flush_rewrite() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
和
flush_rewrite_rules(false);
但是没什么好看的。
那么,有谁可以帮助我?如果您需要更多信息,请告诉我,因为我真的想解决这个问题!
答案 0 :(得分:0)
首先转到设置>永久链接并选择普通的固定链接并保存设置。然后转到仪表板并查看您的分类,然后将您的永久链接设置恢复为帖子名称并保存您的永久链接设置...希望这将解决您的问题...因为您的所有代码和模板现在看起来很好...希望适合你