首页 > 解决方案 > 如何命名页面以访问我的分类/术语

问题描述

我创建了自己的 customposttype

结构:专辑——专辑类型(英格兰、岛屿、法国……)

在管理菜单中,我可以很好地填写它(项目并填充主菜单)。

但我很困惑如何命名我的(页面/模板)以访问这些项目。要么我被定向到索引页,要么我得到 404 错误。

生成的 slug 如下所示:

localhost/wp_v4/album/island/
localhost/wp_v4/album/england/

……

我尝试将我的页面命名为:

page-album-england.php
page-album-template.php
taxonomy-album-england.php
taxonomy-album.php

我错过了什么???

/*
    ==========================================
     Custom Post Type
    ==========================================
*/
function mkseventeen_custom_post_type (){

    $labels = array(
        'name' => 'Album',
        'singular_name' => 'Album',
        'add_new' => 'Add Item',
        'all_items' => 'All Items',
        'add_new_item' => 'Add Item',
        'edit_item' => 'Edit Item',
        'new_item' => 'New Item',
        'view_item' => 'View Item',
        'search_item' => 'Search Album',
        'not_found' => 'No items found',
        'not_found_in_trash' => 'No items found in trash',
        'parent_item_colon' => 'Parent Item'
    );
    $args = array(
        'labels' => $labels,
        'public' => true,
        'has_archive' => true,
        'publicly_queryable' => true,
        'query_var' => true,
        //'rewrite' => true,
        'rewrite' => array( 'slug' => 'album' ),
        'capability_type' => 'post',
        'hierarchical' => false,
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'thumbnail',
            'revisions',
        ),
        'taxonomies' => array('Albumtyp', 'post_tag'),  
        'menu_position' => 5,
        'exclude_from_search' => false
    );
    register_post_type('album',$args);
}
add_action('init','mkseventeen_custom_post_type');

function mkseventeen_custom_tayonomies(){
    // add new taxonomies hierarchical
    $labels = array(
        'name' => 'Albumtyp',  
        'singular_name' => 'Albumtyp',
        'search_items' => 'Search Albumtyp',
        'all_items' => 'All Albumtyps',   
        'parent_item' => 'Parent Albumtyp',
        'parent_item_colon' => 'Parent Albumtyp:',
        'edit_item' => 'Edit Albumtyp',
        'update_item' => 'Update Albumtyp',
        'add_new_item' => 'Add New Work Albumtyp',
        'new_item_name' => 'New Albumtyp Name',
        'menu_name' => 'Albumtyp'
    );

    $args= array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'rewrite' => array('slug' => 'albumtyp')
    );
    register_taxonomy('Albumtyp', array('album'), $args);

}

add_action('init', 'mkseventeen_custom_tayonomies');

标签: wordpress

解决方案


它在我使用时有效:

单张专辑.php

附录:

我用新名称重新制作了完全相同的结构,突然间达到了预期的目标。

我将专辑重命名为投资组合,并将专辑类型的术语重命名为 klasse。现在我可以通过以下方式访问该帖子:

分类-klasse.php

如法典中所述。

有趣,但现在它起作用了......


推荐阅读