以前に尋ねられた質問がありますが、どの回答も私の問題を解決してくれませんでした。それは私が以前に遭遇したものですが、解決することができませんでした。
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。
しかし、どういうわけかワードプレスは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);
しかし、何も役に立たないようです。
それで、私を助けることができる人はいますか?さらに情報が必要な場合は、教えてください。この問題を本当に解決したいからです。