doupuxuan5784 2017-03-07 14:12
浏览 10
已采纳

分类模板不适用于自定义帖子类型

I created a Custom post type and added a taxonomy, but the template (taxonomy.php or taxonomy-provincies.php) isn't working. All I get is a 404 error.

I already tried saving the permalink settings to help reset the permalink issue.

What am I doing wrong here?

Code for Custom post type

/* Custom post type for 'Bedrijven' */

add_action( 'init', 'custom_post_bedrijven' );
function custom_post_bedrijven() {

    $labels = array(
        'name'                  => __('Bedrijven', 'post type general name'),
        'singular_name'         => __('Bedrijf', 'post type singular name'),
        'add_new'               => __('Nieuwe bedrijf'),
        'add_new_item'          => __('Bedrijf toevoegen'),
        'edit_item'             => __('Bedrijf bewerken'),
        'new_item'              => __('Nieuwe bedrijf'),
        'all_items'             => __('Bedrijven'),
        'view_item'             => __('Bedrijven bekijken'),
        'search_items'          => __('Bedrijven zoeken'),
        'not_found'             => __('Geen bedrijven gevonden'),
        'not_found_in_trash'    => __('Geen bedrijven gevonden in archief'),
        'parent_item_colon'     => '',
        'menu_name'             => 'Bedrijven'
    );

    $supports = array (
        'title', 'editor', 'page-attributes'
    );

    $details = array (
        'labels'            => $labels,
        'label'             => 'Bedrijven',
        'capability_type'   => 'post',
        'description'       => 'Custom post type voor bedrijven',
        'public'            => true,
        'publicly_queryable'=> true,
        'show_ui'           => true, 
        'show_in_admin_bar' => true,
        'query_var'         => true,
        'hierarchical'      => true,
        'has_archive'       => true,
        'exclude_from_search' => false,
        'supports'          => $supports,
        'rewrite'           => array (
            'slug'          => 'bedrijven',
            'with_front'    => false,
        ),
        'menu_icon'         => 'dashicons-store',
        'taxonomies'        => array(
            'bedrijven_provincies'
        )
    );

    register_post_type( 'bedrijven', $details );
    flush_rewrite_rules();
}

Code for added Taxonomy

/* Custom taxonomy 'provincies' for CPT 'bedrijven' */

add_action('init', 'custom_bedrijven_provincies');
function custom_bedrijven_provincies() {

    $labels = array(
        'name'              => _x('Provincies', 'post type general name'),
        'singular_name'     => _x('Provincie', 'post type singular name'),
        'add_new'           => _x('Nieuwe provincie', 'client'),
        'add_new_item'      => __('Provincie toevoegen'),
        'edit_item'         => __('Provincie bewerken'),
        'new_item'          => __('Nieuwe provincie'),
        'view_item'         => __('Provincie bekijken'),
        'search_items'      => __('Provincie zoeken'),
        'not_found'         => __('Geen provincie gevonden'),
        'not_found_in_trash' => __('Geen provincie gevonden in archief')
    );

    $args = array(
        'labels'                => $labels,
        'hierarchical'          => true,
        'show_ui'               => true,
        'query_var'             => true,
        'show_in_nav_menus'     => true,
        'rewrite'               => array(
            'slug' => 'bedrijven_provincies',
            'with_front' => false,
        )
    );

    register_taxonomy('bedrijven_provincies', array('bedrijven'), $args);
    flush_rewrite_rules( false );
}
  • 写回答

1条回答 默认 最新

  • dongliang9682 2017-03-07 14:20
    关注

    I think there will be the permalink issue. Please go to this path settings >> Permalinks and save this setting again.., I am sure URL will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥30 python安卓开发
  • ¥15 使用R语言GD包一直不出结果
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码
  • ¥15 stm32标准库的PID角度环