自定义帖子类型的分类

时间:2011-07-13 作者:George Jipa

嘿伙计们,

我的分类法有一些问题。。。这是我的代码:

<?php 
define(\'REVIEWS_SLUG\', \'review\');
define(\'REVIEWS_CATEGORY_SLUG\', \'review-category\');

function create_reviews_section(){                                    
  $labels = array(
    \'name\' => __(\'Reviews\'),
    \'singular_name\' => __(\'review\'),
    \'add_new\' => __(\'Add New\'),
    \'add_new_item\' => __(\'Add New Review\'),
    \'edit\' => __(\'Edit\'),
    \'edit_item\' => __(\'Edit Review\'),
    \'new_item\' => __(\'New Review\'),
    \'view\' => __(\'View\'),
    \'view_item\' => __(\'View Review\'),
    \'search_items\' => __(\'Search Reviews\'),
    \'not_found\' => __(\'No reviews found\'),
    \'not_found_in_trash\' => __(\'No reviews found in Trash\'),
  );

  register_post_type(\'reviews\', array(
        \'labels\' => $labels,
        \'description\' => __(\'Reviews Section\'),
        \'public\' => true,
        \'show_ui\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'supports\' => array(\'title\', \'editor\', \'custom-fields\', \'excerpt\', \'comments\', \'author\'),
        \'rewrite\' => array(\'slug\' => REVIEWS_SLUG, \'with_front\' => true),
        \'query_var\' => false,
    \'taxonomies\' => array(\'review-category\')        
      )
  );    
}

function create_review_category(){ 
  $labels = array(
    \'name\' => _x(\'Review Categories\', \'Review Categories\'),
    \'singular_name\' => _x(\'Review Category\', \'Review Category\'),
    \'search_items\' =>  __(\'Search Review Categories\'),
    \'popular_items\' => __(\'Popular Review Categories\'),
    \'all_items\' => __(\'All Review Categories\'),
    \'edit_item\' => __(\'Edit Review Category\'), 
    \'update_item\' => __(\'Update Review Category\'),
    \'add_new_item\' => __(\'Add New Review Category\'),
    \'new_item_name\' => __(\'New Review Category\'),
    \'separate_items_with_commas\' => __(\'Separate review categories with commas\'),
    \'add_or_remove_items\' => __(\'Add or remove review categories\'),
    \'choose_from_most_used\' => __(\'Choose from the most used review categories\'),
    \'menu_name\' => __(\'Categories\')
  ); 

  register_taxonomy(\'review-category\', array(\'reviews\'), array(
    \'hierarchical\' => true,
    \'labels\' => $labels,
    \'show_ui\' => true,
    \'query_var\' => true,
    \'rewrite\' => array(\'slug\' => REVIEWS_CATEGORY_SLUG),
  ));
}
第一个问题是WordPress不认为这种分类法是分层的。例如,当我使用此分类法生成下拉列表时depth="1", 它不会返回所有分类法(父分类法和子分类法)。

第二个问题,当我尝试插入一个新术语时(使用wp_insert_term) WordPress告诉我分类法无效。

第三个问题,我认为子分类url将类似于:示例。com/review-category/parent-taxonomy/child-taxonomy/但在我的例子中是:示例。com/审查类别/子分类法/。我怎样才能将url修改成这样?

提前感谢;)

LE:

<?php
add_action(\'init\', \'create_reviews_section\');
add_action(\'init\', \'create_review_category\', 0);

$args = array(
  \'show_option_none\' => \'Choose make\',
  \'hide_empty\' => 0,
  \'name\' => \'vehicle_category\',
  \'id\' => \'vehicle_category\',
  \'taxonomy\' => \'review-category\',
  \'hierarchical\' => 0,
  \'class\' => \'maxw\',
  \'depth\' => 1
); 
wp_dropdown_categories( $args );

1 个回复
最合适的回答,由SO网友:tollmanz 整理而成

对于第一个问题,阅读法典中的以下内容让我觉得你需要改变hierarchical 至1:

深度(整数)(可选)最大深度。除非Hierarchy设置为true,否则此选项为ignore。默认值:0/False

分层(布尔)(可选)显示所有类别(0/False)或显示类别(1/True),深度为“depth”。默认值:0/False

结束

相关推荐