1

我在创建自定义分类时遇到问题。

问题是,我使用的是 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 --*/

?>

请帮帮我。提前致谢。

4

1 回答 1

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 
),
));
}
于 2016-06-17T18:47:02.263 回答