自定义分类模板未显示

时间:2012-07-25 作者:Ian Hoar

我花了一天的大部分时间试图弄明白这一点。我的自定义分类显示在WordPress admin中,我可以将其添加到nav并使用wp\\u nav\\u菜单显示,但当我单击任何术语时,我会得到404,即使我有一个分类。主题中的php。有什么想法吗?

/** Product custom post type **/
add_action( \'init\', \'product_post_type\' );
function product_post_type() {
  register_post_type( \'product\',
    array(
      \'labels\' => array(
        \'name\' => __( \'Products\' ),
        \'singular_name\' => __( \'Product\' ),
        \'add_new_item\' => __( \'Add New Product\' ),
        \'new_item\' => __(\'New Product\'),
        \'all_items\' => __( \'All Products\' ),
        \'view_item\' => __(\'View Products\' ),
        \'search_items\' => __(\'Search Products\'),
        \'not_found\' =>  __(\'No Products found\'),
        \'not_found_in_trash\' => __(\'No Products found in Trash\'), 
        \'parent_item_colon\' => \'\',
        \'menu_name\' => __(\'Products\')
      ),
    \'menu_position\' => 5,
    \'public\' => true,
    \'taxonomies\' => array(\'product\')
    )
  );
}

/** product Taxonomy **/

add_action( \'init\', \'create_product_taxonomy\' );

function create_product_taxonomy() 
{
  $labels = array(
    \'name\' => __( \'Product Categories\' ),
    \'singular_name\' => __( \'Product Category\' ),
    \'search_items\' =>  __( \'Search Product Categories\' ),
    \'all_items\' => __( \'All Product Categories\' ),
    \'parent_item\' => __( \'Parent Product Category\' ),
    \'parent_item_colon\' => __( \'Parent Product Category:\' ),
    \'edit_item\' => __( \'Edit Product Category\' ), 
    \'update_item\' => __( \'Update Product Category\' ),
    \'add_new_item\' => __( \'Add Product Category\' ),
    \'new_item_name\' => __( \'New Product Category\' ),
    \'menu_name\' => __( \'Product Categories\' ),
  );    

  register_taxonomy(\'product\', array(\'product\'), array(
    \'public\' => true,
    \'hierarchical\' => true,
    \'labels\' => $labels,
    \'query_var\' => true
  ));
}

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

好吧,我觉得很傻,但归根结底,你不能有一个自定义的帖子类型和同名的自定义分类法。(嗯……你可以,但你的分类法模板不起作用)在我的例子中,我将我的内容类型更改为“产品”,将我的分类法更改为“产品”。这将修复所有问题,并进行永久链接刷新。

结束

相关推荐