我有我的度假村页面page-resorts.php
的URL:
http://localhost/testwordpress/resorts/
单击度假村自定义页面下的帖子链接后,我将获得自定义页面模板(CPT)single-resort.php
的URL:
http://localhost/testwordpress/resort/kurumba-maldives/
你可以看到resorts
改为resort
,因为我不能使用resorts
slug作为slug post。
我怎样才能实现这种URL:
http://localhost/testwordpress/resorts/kurumba-maldives/
在哪里使用resorts
字而不是resort
字?
我听说过自定义slu and并搜索它,但我仍然无法理解它。
您可以通过这种方式创建自定义帖子类型。
function create_posttype() {
register_post_type( 'resort',
array(
'labels' => array(
'name' => __( 'Resorts' ),
'singular_name' => __( 'Resort' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'resorts'),
)
);
}
add_action( 'init', 'create_posttype' );
'rewrite'=> array('slug'=>'resorts'),这用于在URL上添加slur。这样你就可以实现你的URL。
或者你可以在functions.php中覆盖你当前的slug
add_filter( 'register_post_type_args', 'wpse247328_register_post_type_args', 10, 2 );
function wpse247328_register_post_type_args( $args, $post_type ) {
if ( 'resort' === $post_type ) {
$args['rewrite']['slug'] = 'resorts';
}
return $args;
}
有关更多信息,请访问。