【发布时间】:2026-02-04 00:15:02
【问题描述】:
我正在建立一个网站,但不知道如何仅为我的自定义帖子类型更改永久链接结构!
我目前有一个名为“产品”的自定义帖子类型,其 URL 结构如下
/products/continental-rack/
我的自定义帖子类型的完整代码如下:
function cpt_products() {
$labels = array(
'name' => 'Products',
'singular_name' => 'Product',
'menu_name' => 'Products',
'name_admin_bar' => 'Product',
'add_new' => 'Add New',
'add_new_item' => 'Add New Product',
'new_item' => 'New Product',
'edit_item' => 'Edit Product',
'view_item' => 'View Product',
'all_items' => 'All Products',
'search_items' => 'Search Products',
'parent_item_colon' => 'Parent Product',
'not_found' => 'No Products Found',
'not_found_in_trash' => 'No Products Found in Trash'
);
$args = array(
'labels' => $labels,
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-tag',
'capability_type' => 'post',
'taxonomies' => array( 'category' ),
'hierarchical' => false,
'supports' => array( 'title', 'author', 'thumbnail' ),
'has_archive' => true,
'rewrite' => array( 'slug' => 'products' ),
'query_var' => true
);
register_post_type( 'products', $args );
}
add_action( 'init', 'cpt_products' );
我已启用右侧的类别部分,以便在选中一个类别时,我无法获得该类别以在Permalink结构中出现。
所以我想要的永久链接结构本质上是这样的:
/%category-name%/products/continental-rack/
只是找不到办法。任何帮助将不胜感激!
【问题讨论】:
标签: php wordpress wordpress-theming backend permalinks