我有一个名为“服务”的自定义帖子类型,其中有一个名为“service\\u areas”的类别,我希望能够打开一个列出所有“service\\u areas”的页面。我不太确定这个页面的名称,因为我认为“分类归档页面”是一个列出某个特定“service\\u领域”中所有帖子的页面。
调用urldomain-name.com/service_areas/a_service_category
为a_service_category
按预期分类。
什么是制作的好方法domain-name.com/service_areas
调出一个页面,列出所有“service\\u区域”(与404相对)?
更多详细信息:
自定义帖子类型为services
它的自定义分类是services_category
带着一点service_areas
:
/*
* Create Services CPT
*/
function services_post_type() {
// Set UI labels for Custom Post Type
$labels = array(
\'name\' => _x( \'Services\', \'Post Type General Name\', \'total\' ),
\'singular_name\' => _x( \'Service\', \'Post Type Singular Name\', \'total\' ),
\'menu_name\' => __( \'Services\', \'total\' ),
\'parent_item_colon\' => __( \'Parent Service\', \'total\' ),
\'all_items\' => __( \'All Services\', \'total\' ),
\'view_item\' => __( \'View Service\', \'total\' ),
\'add_new_item\' => __( \'Add New Service\', \'total\' ),
\'add_new\' => __( \'Add New\', \'total\' ),
\'edit_item\' => __( \'Edit Service\', \'total\' ),
\'update_item\' => __( \'Update Service\', \'total\' ),
\'search_items\' => __( \'Search Service\', \'total\' ),
\'not_found\' => __( \'Not Found\', \'total\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'total\' ),
);
$args = array(
\'label\' => __( \'services\', \'total\' ),
\'description\' => __( \'Services we offer\', \'total\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'revisions\' ),
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_icon\' => \'dashicons-businessman\',
\'menu_position\' => 20,
\'can_export\' => true,
\'rewrite\' => array( \'slug\' => \'services\' ),
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'capability_type\' => \'post\',
);
// Registering your Custom Post Type
register_post_type( \'services\', $args );
}
/**
* Register Caregiver category.
*
*/
function register_categories() {
// Define and sanitize options
$name = __( \'Service Categories\', \'total\' );
$slug = \'service_areas\';
$args = array(
\'labels\' => array(
\'name\' => $name,
\'singular_name\' => $name,
\'menu_name\' => $name,
\'search_items\' => __( \'Search\',\'total\' ),
\'popular_items\' => __( \'Popular\', \'total\' ),
\'all_items\' => __( \'All\', \'total\' ),
\'parent_item\' => __( \'Parent\', \'total\' ),
\'parent_item_colon\' => __( \'Parent\', \'total\' ),
\'edit_item\' => __( \'Edit\', \'total\' ),
\'update_item\' => __( \'Update\', \'total\' ),
\'add_new_item\' => __( \'Add New\', \'total\' ),
\'new_item_name\' => __( \'New\', \'total\' ),
\'separate_items_with_commas\' => __( \'Separate with commas\', \'total\' ),
\'add_or_remove_items\' => __( \'Add or remove\', \'total\' ),
\'choose_from_most_used\' => __( \'Choose from the most used\', \'total\' ),
),
\'public\' => true,
\'show_in_nav_menus\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => true,
\'hierarchical\' => true,
\'rewrite\' => array( \'slug\' => $slug, \'with_front\' => false ),
\'query_var\' => true
);
register_taxonomy( \'services_category\', array( \'services\' ), $args );
}
add_action( \'init\', \'services_post_type\', 0 );
add_action( \'init\', \'register_categories\', 0 );
==================
我注意到如果我过滤“pre\\u get\\u posts”,$query->query[\'name\'] == \'service_areas\'
对于该url为true。我可能会加载一个基于该测试的自定义模板并循环通过get_terms( \'service_areas\' )
, 但我不知道怎么做。