这让我发疯,我敢肯定这很简单,但是我所寻找的没有一个简单的结构(一切都非常复杂)。
我有一个自定义帖子类型product_listing
和一个自定义分类法product_cat
(属于分层结构,应该具有类似的类别)。
我只是希望我的网址看起来像这样:
mysite.com/products/category1/product-name1
mysite.com/products/category2/product-name2
但是对于我的一生,无论我做什么,我都会遇到可怕的404问题。页面可以正常工作,而帖子可以正常工作,但是我的自定义帖子无法正常工作。它们显示为:
mysite.com/products/product-name1
mysite.com/products/product-name2
哪个有效!只是我想在那里查看我的自定义分类法,而且我希望能够访问以下步骤访问taxonomy.php
已设置的模板:
mysite.com/products/category1/
mysite.com/products/category2/
我的都不是一样的,我也不希望自己是。这是我functions.php
文件的帖子类型和分类法部分:
///// CUSTOM POST TYPES /////
// register the new post type
register_post_type( 'product_listing', array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Create New Product' ),
'edit' => __( 'Edit' ),
'edit_item' => __( 'Edit Product' ),
'new_item' => __( 'New Product' ),
'view' => __( 'View Products' ),
'view_item' => __( 'View Product' ),
'search_items' => __( 'Search Products' ),
'not_found' => __( 'No products found' ),
'not_found_in_trash' => __( 'No products found in trash' ),
'parent' => __( 'Parent Product' ),
),
'description' => __( 'This is where you can create new products on your site.' ),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 2,
'menu_icon' => get_stylesheet_directory_uri() . '/images/tag_orange.png',
'hierarchical' => true,
'_builtin' => false, // It's a custom post type, not built in!
'rewrite' => array( 'slug' => 'products', 'with_front' => true ),
'query_var' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ),
) );
//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_product_taxonomies', 0 );
//add_action('admin_init', 'flush_rewrite_rules');
//create two taxonomies, genres and writers for the post type "book"
function create_product_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Categories' ),
'parent_item_colon' => __( 'Parent Categories:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
'menu_name' => __( 'Category' ),
);
register_taxonomy( 'product_cat', array( 'product_listing' ), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
//'rewrite' => true,
'rewrite' => array( 'slug' => '%category%', 'with_front' => true ),
) );
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Scents', 'taxonomy general name' ),
'singular_name' => _x( 'Scent', 'taxonomy singular name' ),
'search_items' => __( 'Search Scents' ),
'popular_items' => __( 'Popular Scents' ),
'all_items' => __( 'All Scents' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Scent' ),
'update_item' => __( 'Update Scent' ),
'add_new_item' => __( 'Add New Scent' ),
'new_item_name' => __( 'New Scent Name' ),
'separate_items_with_commas' => __( 'Separate scents with commas' ),
'add_or_remove_items' => __( 'Add or remove scents' ),
'choose_from_most_used' => __( 'Choose from the most used scents' ),
'menu_name' => __( 'Scents' ),
);
register_taxonomy( 'scent', 'product_listing', array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
//'rewrite' => array( 'slug' => 'scents' ),
) );
}
我也有另一个自定义分类法,scents
理想情况下,我想拥有一些友好的网址,但是对此我更加开放。我可能想通过以下方式访问所有气味的列表,mysite.com/products/scents
但它们不必特定于类别。
有谁能够帮助我?