1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | //WordPress 自定义分类、标签、页面的URL伪静态格式,加.html后缀 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' ); //WordPress 自定义文章类型video以id.html重写 add_filter('post_type_link', 'custom_video_link', 1, 3); function custom_video_link( $link, $post = 0 ){ if ( $post->post_type == 'video' ){ return home_url( 'video/' . $post->ID .'.html' ); } else { return $link; } } add_action( 'init', 'video_rewrites_init' ); function video_rewrites_init(){ add_rewrite_rule( 'video/([0-9]+)?.html$', 'index.php?post_type=video&p=$matches[1]', 'top' ); add_rewrite_rule( 'video/([0-9]+)?.html/comment-page-([0-9]{1,})$', 'index.php?post_type=video&p=$matches[1]&cpage=$matches[2]', 'top' ); } |
原文链接:https://xiaohost.com/3387.html,转载请注明出处。
评论2