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

2020年2月12日 / 网站源码 / 1条 / 3,852次

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

  1. function custom_page_rules() {
  2. global $wp_rewrite;
  3. /** page页面自定义URL样式 **/
  4. $wp_rewrite->page_structure = $wp_rewrite->root . 'page/%pagename%.html';
  5. /** tag页面自定义URL样式 **/
  6. $wp_rewrite->extra_permastructs['post_tag']['with_front'] = '';
  7. $wp_rewrite->extra_permastructs['post_tag']['struct'] = $wp_rewrite->extra_permastructs['post_tag']['with_front'] . 'tag/%post_tag%.html';
  8. /** category页面自定义URL样式 **/
  9. $wp_rewrite->extra_permastructs['category']['with_front'] = 'category';
  10. $wp_rewrite -> extra_permastructs['category']['struct'] = $wp_rewrite->extra_permastructs['category']['with_front'].'/%category%.html';
  11. }
  12. add_action( 'init', 'custom_page_rules' );

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

  1. function custom_page_rules() {
  2. global $wp_rewrite;
  3. /** page页面自定义URL样式 **/
  4. $wp_rewrite->page_structure = $wp_rewrite->root . 'page/%pagename%.html';
  5. /** tag页面自定义URL样式 **/
  6. $wp_rewrite->extra_permastructs['post_tag']['with_front'] = '';
  7. $wp_rewrite->extra_permastructs['post_tag']['struct'] = $wp_rewrite->extra_permastructs['post_tag']['with_front'] . 'tag/%post_tag%.html';
  8. /** category页面自定义URL样式 **/
  9. $wp_rewrite->extra_permastructs['category']['with_front'] = 'category';
  10. $wp_rewrite -> extra_permastructs['category']['struct'] = $wp_rewrite->extra_permastructs['with_front'].'/%category%.html';
  11. }
  12. add_action( 'init', 'custom_page_rules' );

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

  1. 小马说道:

    你好


提交评论