【发布时间】:2020-11-04 03:44:42
【问题描述】:
您好,请在下面查看我的要求。
首先,我注册了一个CPT“目录”,其名称为“目录”。另外,我已经注册了一个自定义分类法“business_category”。我想在永久链接结构下面。
- CPT 存档链接:www.domain.com/directory/
- 分类链接:www.domain.com/directory/category/TAXONOMY_NAME/
- 彩管单页:www.domain.com/directory/POST_NAME
所以,我使用了下面的代码。
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->PT = 'cc-directory';
$this->name = 'Directory';
$this->singular_name = 'Directory';
$this->slug = 'directory';
}
public function register_post_type() {
// Get supported features for Directory post type
$supports = apply_filters('cc_directory_supports', array('editor', 'title','thumbnail'));
$labels = array(
'name' => $this->name,
'singular_name' => $this->singular_name,
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . $this->singular_name,
'edit_item' => 'Edit ' . $this->singular_name,
'new_item' => 'New ' . $this->singular_name,
'all_items' => 'All ' . $this->name,
'view_item' => 'View ' . $this->name,
'search_items' => 'Search ' . $this->name,
'not_found' => 'No ' . strtolower($this->name) . ' found',
'not_found_in_trash' => 'No ' . strtolower($this->name) . ' found in Trash',
'parent_item_colon' => '',
'menu_name' => $this->name
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => $this->slug ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => 11,
'menu_icon' => 'dashicons-book',
'supports' => $supports,
'yarpp_support' => true
);
register_post_type( $this->PT, $args );
$plural_label = 'Categories';
$singular_label = 'Category';
register_taxonomy(
'business_category',
$this->PT,
array(
'label' => $plural_label,
'labels' => array(
'name' => $plural_label,
'singular_name' => $singular_label,
'all_items' => sprintf(__('All %s', 'claritycloud-directory'), $plural_label),
'edit_item' => sprintf(__('Edit %s', 'claritycloud-directory'), $singular_label),
'view_item' => sprintf(__('View %s', 'claritycloud-directory'), $singular_label),
'update_item' => sprintf(__('Update %s', 'claritycloud-directory'), $singular_label),
'add_new_item' => sprintf(__('Add New %s', 'claritycloud-directory'), $singular_label),
'new_item_name' => sprintf(__('New %s Name', 'claritycloud-directory'), $singular_label),
'popular_items' => sprintf(__('Popular %s', 'claritycloud-directory'), $plural_label),
'search_items' => sprintf(__('Search %s', 'claritycloud-directory'), $plural_label),
),
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
'hierarchical' => true,
'rewrite' => array('slug' => 'business-category'),
)
);
}
现在我的网址是:
- http://localhost/demo-project/directory/
- http://localhost/demo-project/business-category/antiques/
- http://localhost/demo-project/directory/a-lil-bit-of-sas/
如下所示:
- http://localhost/demo-project/directory/
- http://localhost/demo-project/directory/category/antiques/
- http://localhost/demo-project/directory/a-lil-bit-of-sas/
只需要修改上面的第二个网址。
谁能给我建议?
谢谢, 苏汉卡
【问题讨论】:
-
请告诉我。
标签: url-rewriting permalinks slug