2013-10-08 69 views
1

我在創建自定義分類標準時遇到問題。創建自定義分類標準

問題是,我使用的是zenshop wordpress主題。還有就是要增加產品的選擇,但是當你發佈產品發佈的產品的網址是這樣

example.com/products/my-post-title ,我希望它像 example.com/mobiles/我-後標題

同樣,

當我創建一個類別中成爲,

example.com/product-category/name-of-category ,我希望它像 例子.com /列表/名稱的類別

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 --*/ 

?>

請幫助我。提前致謝。

回答

0

代碼爲自定義分類

add_action('init', 'add_my_taxonomies', 0); 
function add_years_taxonomies() { 
register_taxonomy('years', 'repository', array(
'hierarchical' => true,'labels' => array('labels' => array(
    'name' => _x('Years', 'taxonomy general name'), 
    'singular_name' => _x('Year', 'taxonomy singular name'), 
    'search_items' => __('Search Years'), 
    'all_items' => __('All Years'), 
    'parent_item' => __('Parent '), 
    'parent_item_colon' => __('Parent Year:'), 
    'edit_item' => __('Edit Year'), 
    'update_item' => __('Update Year'), 
    'add_new_item' => __('Add New Year'), 
    'new_item_name' => __('New Year Name'), 
    'menu_name' => __('Years'), 
), 
'rewrite' => array(
    'slug' => 'years', 
    'with_front' => false, 
    'hierarchical' => true 
), 
)); 
} 
相關問題