我在创建自定义分类时遇到问题。
问题是,我使用的是 zenshop wordpress 主题。有一个添加产品的选项,但是当您发布产品时,发布产品的 URL 是这样的
example.com/products/my-post-title,我想要它像 example.com/mobiles/my-post-title
相似地,
当我在它中创建一个类别时,
example.com/product-category/name-of-category 我希望它像 example.com/listing/name-of-category
Product.php 代码如下
enter code here<?php
add_action('init', 'project_products_init');
/*-- Custom Post Init Begin --*/
function project_products_init()
{
$labels = array(
'name' => _x('Products', 'post type general name'),
'singular_name' => _x('Product', 'post type singular name'),
'add_new' => _x('Add New', 'product'),
'add_new_item' => __('Add New Product'),
'edit_item' => __('Edit Product'),
'new_item' => __('New Product'),
'view_item' => __('View Product'),
'search_items' => __('Search Products'),
'not_found' => __('No products found'),
'not_found_in_trash' => __('No products found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'Products'
);
$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','custom-fields','comments')
);
// The following is the main step where we register the post.
register_post_type('products',$args);
// Initialize New Taxonomy Labels
$labels = array(
'name' => _x( 'Category', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Category' ),
'all_items' => __( 'All Category' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
);
// Custom taxonomy for Project Tags
register_taxonomy('product-category',array('products'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'product-category' ),
));
}
/*-- Custom Post Init Ends --*/
?>
请帮帮我。提前致谢。