虽然后台可以设置固定链接以post_id postname 结尾也可以显示.html结构,但是页面一直不得解决办法,下面这个代码就可以轻松解决


add_action('init', 'html_page_permalink', -1);
register_activation_hook(__FILE__, 'barley_active');
register_deactivation_hook(__FILE__, 'barley_deactive');
function html_page_permalink() {
    global $wp_rewrite;
    if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
        $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
    } 
}
add_filter('user_trailingslashit', 'no_page_slash',66,2);
function no_page_slash($string, $type){
    global $wp_rewrite;
    if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){
        return untrailingslashit($string);
    } else {
        return $string;
    }
}

function barley_active() {
    global $wp_rewrite;
    if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
        $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
    }
    $wp_rewrite->flush_rules();
}
function barley_deactive() {
    global $wp_rewrite;
    $wp_rewrite->page_structure = str_replace(".html","",$wp_rewrite->page_structure);
    $wp_rewrite->flush_rules();
}

首先将这段代码放进functions.php中,然后设置固定链接,以文章名.html 或者ID.html结尾都行,最后更新固定链接即可