wordpress - 如何命名页面以访问我的分类/术语
问题描述
我创建了自己的 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');
解决方案
它在我使用时有效:
单张专辑.php
附录:
我用新名称重新制作了完全相同的结构,突然间达到了预期的目标。
我将专辑重命名为投资组合,并将专辑类型的术语重命名为 klasse。现在我可以通过以下方式访问该帖子:
分类-klasse.php
如法典中所述。
有趣,但现在它起作用了......
推荐阅读
- c# - 同一类型的多个鉴别器
- jinja2 - dbt jinja 中是否有所有*有效*数据库和模式组合的变量列表?
- pdf - iText7 - 无法使用 convertToImage 添加嵌套 SVG
- c - Make file "%.o: %.c" 给出“No rule to make target”
- onenote - 如何在 OneNote 中获取所有 Pages 属性的详细列表?
- nginx - 在 Nginx 的反向代理中为特定静态文件添加缓存?
- airflow-scheduler - 如何限制对airflow.models的访问?
- pandas - 获取最大值、最小值和该最大值、最小值的各自所有者 - Pandas
- python - 如何按此顺序打印有向无环图?
- javascript - 如何通过单击一个按钮使用本地存储删除我的待办事项列表中的项目