WordPress设置分类和页面尾巴带有.HTML后缀方法
ssr
撰写于 2022年 02月 26 日

我们使用过WordPress的朋友肯定是知道的,我们创建的分类目录和页面,都是直接目录名称结尾的,不像页面我们可以设置.HTML或者其他后缀的尾巴。但是,类似在ZBLOG、Typecho等程序好像是可以设置分类和页面的尾巴的,如果是WP如何设置呢?

肯定是有办法的,因为WordPress有万能的插件库。
第一、插件方法
我们看到有些网友有提到是使用插件的。比如可以分别使用 html-in-category-and-pages 和 .html on PAGES 插件来解决这个问题,但是老蒋看到目前这两个插件已经过期多年,甚至前者已经被删除。所以,暂时不考虑用插件的办法。
第二、代码方法
这里我们可以使用代码办法。

// 设置分类,页面,TAG HTML结尾 Edit By itbulu.com
function custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . 'page/%pagename%.html';
$wp_rewrite->extra_permastructs'post_tag' = ”;
$wp_rewrite->extra_permastructs['post_tag']['struct'] = $wp_rewrite-

extra_permastructs'post_tag' . 'tag/%post_tag%.html';
$wp_rewrite->extra_permastructs'category' = 'category';
$wp_rewrite -> extra_permastructs['category']['struct'] = $wp_rewrite->extra_permastructs'category'.'/%category%.html';
}
add_action( 'init', 'custom_page_rules' );

我们可以将代码添加到 Functions.php 页面中启动功能。

WordPress设置分类和页面尾巴带有.HTML后缀方法

我们使用过WordPress的朋友肯定是知道的,我们创建的分类目录和页面,都是直接目录名称结尾的,不像页面我们可以设置.HTML或者其他后缀的尾巴。但是,类似在ZBLOG、Typecho等程序好像是可以设置分类和页面的尾巴的,如果是WP如何设置呢?

肯定是有办法的,因为WordPress有万能的插件库。
第一、插件方法
我们看到有些网友有提到是使用插件的。比如可以分别使用 html-in-category-and-pages 和 .html on PAGES 插件来解决这个问题,但是老蒋看到目前这两个插件已经过期多年,甚至前者已经被删除。所以,暂时不考虑用插件的办法。
第二、代码方法
这里我们可以使用代码办法。

// 设置分类,页面,TAG HTML结尾 Edit By itbulu.com
function custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . 'page/%pagename%.html';
$wp_rewrite->extra_permastructs'post_tag' = ”;
$wp_rewrite->extra_permastructs['post_tag']['struct'] = $wp_rewrite-

extra_permastructs'post_tag' . 'tag/%post_tag%.html';
$wp_rewrite->extra_permastructs'category' = 'category';
$wp_rewrite -> extra_permastructs['category']['struct'] = $wp_rewrite->extra_permastructs'category'.'/%category%.html';
}
add_action( 'init', 'custom_page_rules' );

我们可以将代码添加到 Functions.php 页面中启动功能。

赞 (0)

猜您想看

评论区(暂无评论)

这里空空如也,快来评论吧~

我要评论