【发布时间】:2020-05-07 16:35:09
【问题描述】:
我想为我的自定义帖子类型创建一个独特的设计类别。在这里,我将它设计为主要帖子类型,但相同的设计不适用于默认类别页面所需的类别页面。
我的自定义帖子类型名称 resources 为此我创建了一个单独的设计模板 archive-resources.php,所以它工作正常,但对于我尝试过的自定义帖子类别页面很多方法,但我仍然不会得到结果(创建了单独的分类法,如 category-resources.php)但仍然无法正常工作。
一旦我为我的自定义帖子类型 resources 添加了一个类别作为 hotels 用于 hotels 类别,我获得了默认的帖子类别设计,但我赢了不是什么。我喜欢同样的设计想要自定义帖子类型资源。
这是我的自定义帖子类型functions.php
function custom_resource_type() {
$labels = array(
'name' => _x( 'Resources', 'Post Type General Name', 'gucherry-blog' ),
'singular_name' => _x( 'Resource', 'Post Type Singular Name', 'gucherry-blog' ),
'menu_name' => __( 'Resources', 'gucherry-blog' ),
'parent_item_colon' => __( 'Parent Resource', 'gucherry-blog' ),
'all_items' => __( 'All Resources', 'gucherry-blog' ),
'view_item' => __( 'View Resource', 'gucherry-blog' ),
'add_new_item' => __( 'Add New Resource', 'gucherry-blog' ),
'add_new' => __( 'Add Resource', 'gucherry-blog' ),
'edit_item' => __( 'Edit Resource', 'gucherry-blog' ),
'update_item' => __( 'Update Resource', 'gucherry-blog' ),
'search_items' => __( 'Search Resource', 'gucherry-blog' ),
'not_found' => __( 'Not Found', 'gucherry-blog' ),
'not_found_in_trash' => __( 'Not found in Trash', 'gucherry-blog' ),
);
$args = array(
'label' => __( 'resources', 'gucherry-blog' ),
'description' => __( 'Resource for software products and online', 'gucherry-blog' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
'taxonomies' => array( '' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'menu_icon' => 'dashicons-admin-site-alt2',
'capability_type' => 'page',
);
register_post_type( 'resources', $args );
}
add_action( 'init', 'custom_resource_type', 0 );
function resource_categories_taxonomy() {
$resource_cats = array(
'name' => _x( 'Resource Categories', 'taxonomy general name', 'gucherry-blog' ),
'singular_name' => _x( 'Resource Category', 'taxonomy singular name', 'gucherry-blog' ),
'search_items' => __( 'Search Resource Categories', 'gucherry-blog' ),
'all_items' => __( 'All Resource', 'gucherry-blog' ),
'parent_item' => __( 'Parent Resource', 'gucherry-blog' ),
'parent_item_colon' => __( 'Parent Resource:', 'gucherry-blog' ),
'edit_item' => __( 'Edit Resource', 'gucherry-blog' ),
'update_item' => __( 'Update Resource', 'gucherry-blog' ),
'add_new_item' => __( 'Add New Resource', 'gucherry-blog' ),
'new_item_name' => __( 'New Resource', 'gucherry-blog' ),
'menu_name' => __( 'Resource Categories', 'gucherry-blog' ),
);
register_taxonomy('resource_categories',array('resources'), array(
'hierarchical' => true,
'labels' => $resource_cats,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'resource' ),
));
}
add_action( 'init', 'resource_categories_taxonomy', 0 );
【问题讨论】:
标签: wordpress custom-post-type