我有我的度假村网页page-resorts.php的网址
http://localhost/testwordpress/resorts/
单击Resort自定义页面下的post链接后,我将为我的自定义页面模板(CPT) single-resort.php提供这个URL。
http://localhost/testwordpress/resort/kurumba-maldives/
如您所见,resorts被更改为resort,因为我不能使用resorts段塞作为弹格帖子。
我如何实现这样的URL:
http://localhost/testwordpress/resorts/kurumba-maldives/
在哪里使用resorts单词,而不是只使用resort单词?
我听说过定制的鼻涕虫和寻找它,但我仍然无法理解它。
发布于 2018-09-12 09:27:30
您可以以这种方式创建自定义post类型。
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' );‘重写’=>数组(‘slug’=>‘度假村’),这个用来添加词条的网址。这样,您就可以获得您的URL。
或者您可以在functions.php中覆盖当前的段塞。
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;
}欲知详情,请访问。
https://stackoverflow.com/questions/52290853
复制相似问题