WordPress分类、标签、页面伪静态

2020年2月12日 / 龙哥见解 / 1条 / 3,038次

知更鸟的主题Begin后台设置里虽然有去除category和自建页面添加category的方法,但是我一直想让分类也伪静态加上.html,在网上搜索了下,有以下初始源码,加到主题下的functions.php,然后重新更新固定连接即可实现。

function custom_page_rules() {

global $wp_rewrite;

/** page页面自定义URL样式 **/

$wp_rewrite->page_structure = $wp_rewrite->root . 'page/%pagename%.html';

/** tag页面自定义URL样式 **/

$wp_rewrite->extra_permastructs['post_tag']['with_front'] = '';

$wp_rewrite->extra_permastructs['post_tag']['struct'] = $wp_rewrite->extra_permastructs['post_tag']['with_front'] . 'tag/%post_tag%.html';

/** category页面自定义URL样式 **/

$wp_rewrite->extra_permastructs['category']['with_front'] = 'category';

$wp_rewrite -> extra_permastructs['category']['struct'] = $wp_rewrite->extra_permastructs['category']['with_front'].'/%category%.html';

}

add_action( 'init', 'custom_page_rules' );

但是此方法能解决分类、标签、页面伪静态,但是没有剔除category,加入以下代码后即可实现剔除category然后同样更新固定连接后实现伪静态。

function custom_page_rules() {

global $wp_rewrite;

/** page页面自定义URL样式 **/

$wp_rewrite->page_structure = $wp_rewrite->root . 'page/%pagename%.html';

/** tag页面自定义URL样式 **/

$wp_rewrite->extra_permastructs['post_tag']['with_front'] = '';

$wp_rewrite->extra_permastructs['post_tag']['struct'] = $wp_rewrite->extra_permastructs['post_tag']['with_front'] . 'tag/%post_tag%.html';

/** category页面自定义URL样式 **/

$wp_rewrite->extra_permastructs['category']['with_front'] = 'category';

$wp_rewrite -> extra_permastructs['category']['struct'] = $wp_rewrite->extra_permastructs['with_front'].'/%category%.html';

}

add_action( 'init', 'custom_page_rules' );

“WordPress分类、标签、页面伪静态”有1条评论

  1. 小马说道:

    你好


提交评论