Php Wordpress自定义分类页面
我有一个问题,我见过有人问我,但没有一个答案解决了我的问题。这是我以前遇到过的问题,但从未解决过 我已经安装了一个干净的Wordpress,并且在Php Wordpress自定义分类页面,php,wordpress,rewrite,custom-post-type,custom-taxonomy,Php,Wordpress,Rewrite,Custom Post Type,Custom Taxonomy,我有一个问题,我见过有人问我,但没有一个答案解决了我的问题。这是我以前遇到过的问题,但从未解决过 我已经安装了一个干净的Wordpress,并且在functions.php文件中创建了一个自定义的post类型 register_nav_menu('main', 'Main navigation menu'); function add_custom_post_type() { $labels = array( 'name' => _x('Books', 'post
functions.php
文件中创建了一个自定义的post类型
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);
}
我已经为它们制作了一个归档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();
}
以及:
但似乎没有任何帮助
有人能帮我吗?如果你需要更多信息,请告诉我,因为我真的很想解决这个问题 首先进入设置>永久链接,选择永久链接到Plain并保存设置。然后转到仪表板并查看分类,然后将永久链接设置还原为Post Name并保存永久链接设置。。。希望这能解决你的问题。。。由于您的所有代码和模板现在看起来都很好。。。希望对你有用你也试过在上面发帖吗?
flush_rewrite_rules(false);