这是我的第一个问题,请耐心听我说。我正在尝试设置一个自定义的帖子类型,它有一些与之相关的分类法。每个分类法都是分层的。我想要实现的是一个比现在更好的url结构。我的永久链接设置为默认的“帖子名称”设置。我想要实现的是这样一个目标:领域。com/自定义帖子类型/分类法/类型
最终我得到的是:域名。com/分类法/类型
这本质上是一个职业委员会,我有不同的分类法代表不同的类别。例如,不同类型的工作都有“就业部门”。是否应将这些设置为层次结构?
当我使用一个名为“Custom Post Type Permalinks”的插件时,我可以让它以我想要的方式工作,但我想知道如果没有插件,它是否可能。
以下是我创建的自定义帖子类型插件的代码:
<?php
add_action( \'init\', \'career_forum\' );
// let\'s create the function for the custom type
function career_forum() {
$labels = array(
\'name\' => _x( \'Careers\', \'post type general name\' ),
\'singular_name\' => _x( \'Career Listing\', \'post type singular name\' ),
\'add_new\' => __( \'Add New\', \'career\' ),
\'add_new_item\' => __( \'Add New Career Listing\' ),
\'edit_item\' => __( \'Edit Career Listing\' ),
\'new_item\' => __( \'New Career Listing\' ),
\'view_item\' => __( \'View Career Listing\' ),
\'search_items\' => __( \'Search Careers\' ),
\'not_found\' => __( \'No careers found\' ),
\'not_found_in_trash\' => __( \'No careers found in trash\' ),
\'parent_item_colon\' => \'\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'has_archive\' => true,
\'menu_position\' => 5,
\'rewrite\' => array( \'slug\' => \'careers\', \'with_front\' => false ),
\'supports\' => array( \'title\', \'editor\', \'thumbnail\')
);
register_post_type( \'career_listings\', $args );
}
add_action( \'init\', \'create_career_forum_taxonomies\', 0 );
// function for adding taxonomies for Career Forum
function create_career_forum_taxonomies() {
// Job Sectors
$labels = array(
\'name\' => _x( \'Job Sectors\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Job Sector\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Job Sectors\' ),
\'all_items\' => __( \'All Job Sectors\' ),
\'parent_item\' => __( \'parent Job Sector\' ),
\'parent_item_colon\' => __( \'Parent Job Sector:\' ),
\'edit_item\' => __( \'Edit Job Sector\' ),
\'update_item\' => __( \'Update Job Sector\' ),
\'add_new_item\' => __( \'Add New Job Sector\' ),
\'new_item_name\' => __( \'New Job Sector Name\' ),
);
register_taxonomy( \'job_sector\',
array( \'career_listings\' ),
array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
//\'rewrite\' => array( \'slug\' => \'job-sector\', \'hierarchical\' => true, \'with_front\' => true ),
)
);
// Regions
$labels = array(
\'name\' => _x( \'Regions\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Region\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Regions\' ),
\'all_items\' => __( \'All Regions\' ),
\'parent_item\' => __( \'parent Region\' ),
\'parent_item_colon\' => __( \'Parent Region:\' ),
\'edit_item\' => __( \'Edit Region\' ),
\'update_item\' => __( \'Update Region\' ),
\'add_new_item\' => __( \'Add New Region\' ),
\'new_item_name\' => __( \'New Region Name\' ),
);
register_taxonomy( \'region\',
array( \'career_listings\' ),
array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'region\', \'hierarchical\' => true ),
)
);
// Position Type
$labels = array(
\'name\' => _x( \'Position Types\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Position Type\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Position Types\' ),
\'all_items\' => __( \'All Position Types\' ),
\'parent_item\' => __( \'parent Position Type\' ),
\'parent_item_colon\' => __( \'Parent Position Type:\' ),
\'edit_item\' => __( \'Edit Position Type\' ),
\'update_item\' => __( \'Update Position Type\' ),
\'add_new_item\' => __( \'Add New Position Type\' ),
\'new_item_name\' => __( \'New Position Type Name\' ),
);
register_taxonomy( \'position_type\',
array( \'career_listings\' ),
array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'position-type\', \'hierarchical\' => true ),
)
);
}