我创建了一个自定义的wordpress分类法,它与帖子类型"组合"有关.我创建了一个taxonomy.php模板文件.但是当我尝试查看此分类中的帖子时,会打开一个空白页面.日志为空.我如何解决它?
使用以下代码创建投资组合帖子类型:
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( '?????????' ),
'singular_name' => __( '??????' ),
'add_new' => '???????? ??????',
'add_new_item' => '???????? ????? ??????',
'edit_item' => '????????????? ??????'
),
'public' => true,
'supports' => array('title', 'editor'),
'exclude_from_search' => false,
'taxonomies' => array('portfolio_categories')
)
);
}
Run Code Online (Sandbox Code Playgroud)
并使用以下代码创建portfolio_categories分类:
add_action( 'init', 'create_portfolio_taxonomies', 0 );
function create_portfolio_taxonomies(){
$labels = array(
'name' => _x( '????????? ?????', 'taxonomy general name' ),
'singular_name' => _x( '????????? ??????', 'taxonomy singular name' ),
'search_items' => __( '????? ?? ??????????' ),
'all_items' => __( '??? ?????????' ),
'parent_item' => __( '???????????? ?????????' ),
'parent_item_colon' => __( '???????????? ?????????:' ),
'edit_item' => __( '????????????? ?????????' ),
'update_item' => __( '???????? ?????????' ),
'add_new_item' => __( '???????? ????? ?????????' ),
'new_item_name' => __( '????? ??? ?????????' ),
'menu_name' => __( '????????? ?????' )
);
register_taxonomy('portfolio_categories', array('portfolio'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => 'portfolio_categories',
'rewrite' => array( 'slug' => 'portfolio_categories' )
));
}
Run Code Online (Sandbox Code Playgroud)
你必须在你的主题中创建模板
taxonomy-{yourtaxonomy}-{yourslug}.php
Run Code Online (Sandbox Code Playgroud)
要么
taxonomy-{yourtaxonomy}.php
Run Code Online (Sandbox Code Playgroud)
如果不适合您,请转到设置 - >永久链接并在常用设置下,让我们使用帖子名称.然后单击"保存更改"
| 归档时间: |
|
| 查看次数: |
5518 次 |
| 最近记录: |