WordPress 自定义文章类型 固定链接 使用.html 后缀 图文教程

当我们创建了自定义类型文章之后,默认的`固定链接`即使设置成 /%postname%.html ,自定义文章的后缀也不带.html ,所以我们记录一下通过代码的方式来实现。

比如我们这里使用案例的类型

/jiloc-case/postname //默认url路径

/jiloc-case/postname.html //修改之后的url路径

/**  * 设置多种自定义文章类型的固定链接结构为 post_name.html  */ $mytypes = array(//根据需要添加你的自定义文章类型         'case' => 'jiloc-case', 	'product' => 'jiloc-product', ); add_filter('post_type_link', 'my_custom_post_type_link', 1, 3); function my_custom_post_type_link( $link, $post = 0 ){     global $mytypes;     if ( in_array( $post->post_type,array_keys($mytypes) ) ){         return home_url( $mytypes[$post->post_type].'/' . $post->post_name .'.html' );     } else {         return $link;      } } add_action( 'init', 'my_custom_post_type_rewrites_init' ); function my_custom_post_type_rewrites_init(){     global $mytypes;     foreach( $mytypes as $k => $v ) { 		add_rewrite_rule($v.'/([^/]+).html$','index.php?post_type='.$k.'&name=$matches[1]','top');		     } } 

腾讯云限时秒杀【点击购买】

搬瓦工,CN2高速线路,1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

Vultr$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快【点击购买】!

阿里云香港、新加坡VPS/1核/1G/25G SSD/1T流量/30M带宽/年付¥288【点击购买】

WordPress 自定义文章类型 固定链接 使用.html 后缀 图文教程

`微信`扫码 加好友

链接到文章: https://gkxyz.com/wordpress-zidingyiwenzhangleixing-gudinglianjie-shiyong-html-houzhui-tuwenjiaocheng.html

推荐站点

评论已关闭