WordPress全站伪静态,分别在分类列表页、列表分页、TAG标签、单页、文章页后加html后缀。
效果展示:
分类伪静态:www.域名.com/分类名-1.html
分页伪静态:www.域名.com/分类名-2.html
单页伪静态:www.域名.com/about.html
文章页伪静态:www.域名.com/分类名/127348.html
tag标签伪静态:www.域名.com/tag/标签名-1.html
分页伪静态:www.域名.com/tag/标签名-2.html
使用:
1、主题前端分页调用标签用 <? native_pagenavi() ?>
2、固定连接设置为 域名/%category%/%post_id%.html
3、下方代码添加到 主题 function.php文件中 (代码添加完成后,再后台设置中重新保存固定连接)
————————————————
原文链接:https://blog.csdn.net/qq_39339179/article/details/128612797
//分类 单页 tag 加html 伪静态 【开始】
function custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . '/%pagename%.html';
$wp_rewrite->extra_permastructs['post_tag']['struct'] = 'tag/%post_tag%-1.html';
$wp_rewrite -> extra_permastructs['category']['struct'] = '/%category%-1.html';
}
add_action( 'init', 'custom_page_rules' );
//重定义分页连接 伪静态
add_filter('rewrite_rules_array','add_rewrite_rules');
function add_rewrite_rules($aRules){
$aNewRules = array(
'(.+?)-([0-9]{1,}).html$' =>'index.php?category_name=$matches[1]&paged=$matches[2]',
);
$aNewRules1 = array(
'tag/(.+?)-(\d+).html$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
);
$aRules = $aNewRules + $aRules;
$aRules = $aNewRules1 + $aRules;
return $aRules;
}
add_filter( 'redirect_canonical', 'post_custom_redirect_url');
function post_custom_redirect_url($output){
return false;
}
function native_pagenavi(){
global $wp_query, $wp_rewrite;
$wp_query->query_vars["paged"]; //当前页数
$wp_query->query_vars["category_name"]; //当前分类名
$category = '/'.$wp_query->query["category_name"];
if($wp_query->query["category_name"] == ""){
$tag = $wp_query->query_vars["tag"];
$category = '/tag/'.$tag;
}
$wp_query->query_vars["paged"] > 1 ? $current = $wp_query->query_vars["paged"] : $current = 1;
$pagination = array(
"base" => "",
"format" => "",
"total" => $wp_query->max_num_pages, //最大页数
"current" => $current,
"prev_text" => "« ",
"next_text" => " »"
);
$pagination["base"] =$category."-%#%.html";
if( !empty($wp_query->query_vars["s"]) ) {
$pagination["add_args"] = array("s"=>get_query_var("s"));
}
print_R($pagination);
echo paginate_links($pagination);
}
//分类 单页 tag 加html 伪静态【结束】
测试了,第一种模式,第60行 print_R($pagination); 要删除,否则前端显示有代码,删除后正常。
另外,61行,echo paginate_links($pagination); 要添加上主题的DIV样式,比如:
echo '<div class="posts-nav">'.paginate_links($pagination).'</div>';
【2】要修改模板文件,否则,默认模板文件中的【下一页】不能读取本配置,不生效。好多原因是这个原因造成的全站无法全部静态的原因。
搜索模板文件夹,'prev_text' 和 'next_text' ,找到相关的调用参数,定位好,好准备替换成:
主题前端分页调用标签用 <? native_pagenavi() ?>
同时,把CSS也记录下来,到时在functions.php最后的代码中,给 echo paginate_links($pagination); 添加上CSS样式,以保证调取的分页,和原来的CSS是一致的。比如,发现这一段,调用的CSS是 <div class="navigation">
则,相应的修改为如下:
echo '<div class="navigation">'.paginate_links($pagination).'</div>';
或者是:<div class="posts-nav">,相应修改样式为:
echo '<div class="posts-nav">'.paginate_links($pagination).'</div>';
测试一下,如果有冲突,就是CSS重复定义了,查看一下上面的闭环的代码。各个模板,情况不一样。
另外,有个显示未解决:
在主题的index.php里也调用<? native_pagenavi() ?>后,则网站主页显示最新文章时,网站首页访问正常,但翻页时,第2页显示是https://域名/tag/-2.html,但访问不了。实际应该是https://域名/page/2,依然可以访问。能否添加一条规则,解决首页的分页正确,比如弄成:https://域名/index-2.html,这样的样式?
以下是另一家的解决方案,好像分类还是不正确。
// 分类 单页 tag 加html 伪静态 【开始】
function custom_page_rules() {
global $wp_rewrite;
/** page页面自定义URL样式 **/
$wp_rewrite -> page_structure = $wp_rewrite->root.'/%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' );
// 分类 单页 tag 加html 伪静态【结束】
以下是引用出处:https://blog.csdn.net/qq_39339179/article/details/128612797
WordPress全站伪静态,分别在分类列表页、列表分页、TAG标签、单页、文章页后加html后缀
WordPress全站伪静态方法一
效果展示
分类伪静态 www.域名.com/分类名-1.html
分页伪静态 www.域名.com/分类名-2.html
单页伪静态 www.域名.com/about.html
文章页伪静态 www.域名.com/分类名/127348.html
tag标签伪静态 www.域名.com/tag/标签名-1.html
分页伪静态 www.域名.com/tag/标签名-2.html
使用
1、主题前端分页调用标签用 <? native_pagenavi() ?>
2、固定连接设置为 域名/%category%/%post_id%.html
3、下方代码添加到 主题 function.php文件中 (代码添加完成后,再后台设置中重新保存固定连接)
//分类 单页 tag 加html 伪静态
function custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . '/%pagename%.html';
$wp_rewrite->extra_permastructs['post_tag']['struct'] = 'tag/%post_tag%-1.html';
$wp_rewrite -> extra_permastructs['category']['struct'] = '/%category%-1.html';
}
add_action( 'init', 'custom_page_rules' );
//重定义分页连接 伪静态
add_filter('rewrite_rules_array','add_rewrite_rules');
function add_rewrite_rules($aRules){
$aNewRules = array(
'(.+?)-([0-9]{1,}).html$' =>'index.php?category_name=$matches[1]&paged=$matches[2]',
);
$aNewRules1 = array(
'tag/(.+?)-(\d+).html$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
);
$aRules = $aNewRules + $aRules;
$aRules = $aNewRules1 + $aRules;
return $aRules;
}
add_filter( 'redirect_canonical', 'post_custom_redirect_url');
function post_custom_redirect_url($output){
return false;
}
function native_pagenavi(){
global $wp_query, $wp_rewrite;
$wp_query->query_vars["paged"]; //当前页数
$wp_query->query_vars["category_name"]; //当前分类名
$category = '/'.$wp_query->query["category_name"];
if($wp_query->query["category_name"] == ""){
$tag = $wp_query->query_vars["tag"];
$category = '/tag/'.$tag;
}
$wp_query->query_vars["paged"] > 1 ? $current = $wp_query->query_vars["paged"] : $current = 1;
$pagination = array(
"base" => "",
"format" => "",
"total" => $wp_query->max_num_pages, //最大页数
"current" => $current,
"prev_text" => "« ",
"next_text" => " »"
);
$pagination["base"] =$category."-%#%.html";
if( !empty($wp_query->query_vars["s"]) ) {
$pagination["add_args"] = array("s"=>get_query_var("s"));
}
print_R($pagination);
echo paginate_links($pagination);
}
WordPress全站伪静态方法二、
与方法一类似,不同的是标签使用ID做为 标签分类的链接。
效果展示
分类伪静态 www.域名.com/分类名-1.html
分页伪静态 www.域名.com/分类名-2.html
单页伪静态 www.域名.com/about.html
文章页伪静态 www.域名.com/分类名/127348.html
tag标签伪静态 www.域名.com/tag/标签ID-1.html
分页伪静态 www.域名.com/tag/标签ID-2.html
2.1、主题前端分页调用标签用 <? native_pagenavi() ?>
2.2、固定连接设置为 域名/%category%/%post_id%.html
2.3、function.php文件中添加如下代码来实现使用ID做为 标签分类的链接
add_action('generate_rewrite_rules','tag_rewrite_rules');
add_filter('term_link','tag_term_link',10,3);
add_action('query_vars', 'tag_query_vars');
function tag_rewrite_rules($wp_rewrite){
$new_rules = array(
'tag/(\d+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
'tag/(\d+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
'tag/(\d+)/embed/?$' => 'index.php?tag_id=$matches[1]&embed=true',
'tag/(\d+)/page/(\d+)/?$' => 'index.php?tag_id=$matches[1]&paged=$matches[2]',
'tag/(\d+)/?$' => 'index.php?tag_id=$matches[1]',
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
function tag_term_link($link,$term,$taxonomy){
if($taxonomy=='post_tag'){
return home_url('/tag/'.$term->term_id.'-1.html');
}
return $link;
}
function tag_query_vars($public_query_vars){
$public_query_vars[] = 'tag_id';
return $public_query_vars;
}
2.2、在function.php添加如如下代码
//分类 单页 tag 加html 伪静态
function custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . '/%pagename%.html';
$wp_rewrite -> extra_permastructs['category']['struct'] = '/%category%-1.html';
}
add_action( 'init', 'custom_page_rules' );
//重定义分页连接 伪静态
add_filter('rewrite_rules_array','add_rewrite_rules');
function add_rewrite_rules($aRules){
$aNewRules = array(
'(.+?)-([0-9]{1,}).html$' =>'index.php?category_name=$matches[1]&paged=$matches[2]',
);
$aNewRules1 = array(
'tag/(\d+)-(\d+).html$' => 'index.php?tag_id=$matches[1]&paged=$matches[2]',
);
$aRules = $aNewRules + $aRules;
$aRules = $aNewRules1 + $aRules;
return $aRules;
}
//禁止访问原连接
add_filter( 'redirect_canonical', 'post_custom_redirect_url');
function post_custom_redirect_url($output){
return false;
}
function native_pagenavi(){
global $wp_query, $wp_rewrite;
$category = '/'.$wp_query->query["category_name"];
if($wp_query->query["category_name"] == ""){ //如果分类名获取为空,则获取标签ID 或标签名
$tag = $wp_query->query_vars["tag_id"];
$category = '/tag/'.$tag;
}
$wp_query->query_vars["paged"] > 1 ? $current = $wp_query->query_vars["paged"] : $current = 1;
$pagination = array(
"base" => "",
"format" => "",
"total" => $wp_query->max_num_pages, //最大页数
"current" => $current,
"prev_text" => "« ",
"next_text" => " »"
);
$pagination["base"] = $category."-%#%.html"; //分页连接后加html
if( !empty($wp_query->query_vars["s"]) ) {
$pagination["add_args"] = array("s"=>get_query_var("s"));
}
echo paginate_links($pagination);
}
WordPress全站伪静态方法三、
采用分类层级连接。
效果展示
分类伪静态 www.域名.com/分类名/page-1.html
分页伪静态 www.域名.com/分类名/page-2.html
单页伪静态 www.域名.com/about.html
文章页伪静态 www.域名.com/分类名/子分类/127348.html
tag标签伪静态 www.域名.com/tag/标签ID/page-1.html
分页伪静态 www.域名.com/tag/标签ID/page-2.html
3.1、主题前端分页调用标签用 <? native_pagenavi() ?>
3.2、固定连接设置为 域名/%category%/%post_id%.html
3.3、function.php文件中添加如下代码来实现使用ID做为 标签分类的链接
add_action('generate_rewrite_rules','tag_rewrite_rules');
add_filter('term_link','tag_term_link',10,3);
add_action('query_vars', 'tag_query_vars');
function tag_rewrite_rules($wp_rewrite){
$new_rules = array(
'tag/(\d+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
'tag/(\d+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
'tag/(\d+)/embed/?$' => 'index.php?tag_id=$matches[1]&embed=true',
'tag/(\d+)/page/(\d+)/?$' => 'index.php?tag_id=$matches[1]&paged=$matches[2]',
'tag/(\d+)/?$' => 'index.php?tag_id=$matches[1]',
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
function tag_term_link($link,$term,$taxonomy){
if($taxonomy=='post_tag'){
return home_url('/tag/'.$term->term_id.'/page-1.html');
}
return $link;
}
function tag_query_vars($public_query_vars){
$public_query_vars[] = 'tag_id';
return $public_query_vars;
}
//分类 单页 tag 加html 伪静态
function custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . '/%pagename%.html';
$wp_rewrite -> extra_permastructs['category']['struct'] = '/%category%/page-1.html';
}
add_action( 'init', 'custom_page_rules' );
//重定义分页连接 伪静态
add_filter('rewrite_rules_array','add_rewrite_rules');
function add_rewrite_rules($aRules){
$aNewRules = array(
'(.+?)/page-([0-9]{1,}).html$' =>'index.php?category_name=$matches[1]&paged=$matches[2]',
);
$aNewRules1 = array(
'tag/(\d+)/page-(\d+).html$' => 'index.php?tag_id=$matches[1]&paged=$matches[2]',
);
$aRules = $aNewRules + $aRules;
$aRules = $aNewRules1 + $aRules;
return $aRules;
}
//禁止访问原连接
add_filter( 'redirect_canonical', 'post_custom_redirect_url');
function post_custom_redirect_url($output){
return false;
}
function native_pagenavi(){
global $wp_query, $wp_rewrite;
$category = '/'.$wp_query->query["category_name"];
if($wp_query->query["category_name"] == ""){ //如果分类名获取为空,则获取标签ID 或标签名
$tag = $wp_query->query_vars["tag_id"];
$category = '/tag/'.$tag;
}
$wp_query->query_vars["paged"] > 1 ? $current = $wp_query->query_vars["paged"] : $current = 1;
$pagination = array(
"base" => "",
"format" => "",
"total" => $wp_query->max_num_pages, //最大页数
"current" => $current,
"prev_text" => "« ",
"next_text" => " »"
);
$pagination["base"] = $category."/page-%#%.html"; //分页连接后加html
if( !empty($wp_query->query_vars["s"]) ) {
$pagination["add_args"] = array("s"=>get_query_var("s"));
}
echo paginate_links($pagination);
}
最后说明:这三种方法大同小异,具体也就是连接的层级关系,和使用id或标签名做连接的区别,分类列表页默认为分页的第一页,这样可以避免页面重复,造成权重分散,更利于SEO优化。
======================
以下是引用出处:https://blog.csdn.net/cnpinpai/article/details/132064903
WordPress做权重站:二级目录伪静态写法
我喜欢用WordPress建站,但是每个网站我都会写3个以上的二级目录,为什么了,因为WordPress数据量过大会导致数据库很大很卡,所以这种做法可以减轻数据库的负荷。我一般每个目录的文章达到15万篇就不会再更新了,3个目录加起来大约50万篇左右;二级目录的做法可以递增网站的权重,对网站没有任何影响,但是很多朋友不会写伪静态,下面的代码复制到你的网站即可;
我使用的环境是:linux+CentOS7预装宝塔面板+Nginx 1.15.10+MySQL 5.5.62
location /aa/ {
try_files $uri $uri/ /aa/index.php?$args;
}
location /ab/ {
try_files $uri $uri/ /ab/index.php?$args;
}
location /ac/ {
try_files $uri $uri/ /ac/index.php?$args;
}
location /
{
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
上面是二个目录,其中aa 、 ab 、ac就二级目录,替换成你的目录名称即可;
比如你还想增加一个;就在复制一段:
location /ad/ {
try_files $uri $uri/ /ad/index.php?$args;
}
===================
以下又是一篇文章的解决方案。https://blog.csdn.net/wgj0307wgj/article/details/120853340
【收藏】给WordPress分类目录、标签、页面的url链接添加.html_wordpress设置分类也url_wgj的博客-CSDN博客
个人认为啊,分类页面有没有 .html 后缀都无关紧要,因为分类列表的文章是不断更新的,文章页面添加个 .html 倒是有些用。
个人愚见,此话题不做深入讨论,避免杠精找我理论,杠,就是你说的对。
为了解决部分“强迫症患者”的问题,此文将给你给分类页面、标签页面、独立页面 增加 .html 后缀的方法。
将下面的代码添加至当前使用的WordPress主题的functions.php中即可。
特别注意:添加代码后,到WordPress后台》设置》固定连接,重新保存一下设置。
function xintheme_custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . 'page/%pagename%.html';
$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';
<a href="http://sz.jikebufa.cn/a/202192802.html">秃顶脱发怎么办</a>
$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', 'xintheme_custom_page_rules' );
注意:很多WordPress主题都集成了去除分类标志的功能,特别注意:此功能不可与【去除固定连接中的「category」标志开关】同时使用。
【一】以下是技术测试结果【230906】
【原文出处】:https://blog.csdn.net/wgj0307wgj/article/details/120853340
第一个测试结果:
关于我们【页面】:http://ky.hsx.ltd/page/about-us.html
文章分类【文章】:http://ky.hsx.ltd/category/product.html
文章分类【父级】:http://ky.hsx.ltd/category/news.html
文章分类【子级】:http://ky.hsx.ltd/category/news/industry-news.html
文章分类【孙级】:http://ky.hsx.ltd/category/news/industry-news/company-news.html
带分页的:
第1页:http://ky.hsx.ltd/category/news/industry-news.html
第2页:http://ky.hsx.ltd/category/news/industry-news.html/page/2
第3页:http://ky.hsx.ltd/category/news/industry-news.html/page/3
在主题 function.php文件最后添加:
//给WordPress分类目录、标签、页面的url链接添加.html。【改自:https://blog.csdn.net/wgj0307wgj/article/details/120853340。原来多一行URL,报错后删除即好!】
function xintheme_custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . 'page/%pagename%.html';
$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';
$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', 'xintheme_custom_page_rules' );
记得,一定要关闭 插件【WPJAM】中的【增强优化】的分类链接简化【】去掉分类目录链接中的 category。的勾,不可以选择。否则,失效!一直找不到原因,费了老大事才找到这个原因的。
【第一个测试完毕】
【二】以下是技术测试结果【230906】
【原文出处】:https://blog.csdn.net/qq_39339179/article/details/128612797
第二个测试结果:
关于我们【页面】:http://ky.hsx.ltd/about-us.html
文章分类【文章】:http://ky.hsx.ltd/product-1.html
文章分类【父级】:http://ky.hsx.ltd/news-1.html
文章分类【子级】:http://ky.hsx.ltd/news/industry-news-1.html
文章分类【孙级】:http://ky.hsx.ltd/news/industry-news/company-news-1.html
带分页的:
第1页:http://ky.hsx.ltd/news/industry-news-1.html
第2页:http://ky.hsx.ltd/news/industry-news-1.html/page/2
第3页:http://ky.hsx.ltd/news/industry-news-1.html/page/3
在主题 function.php文件最后添加:
//【测试:WordPress全站伪静态,分别在分类列表页、列表分页、TAG标签、单页、文章页后加html后缀,https://blog.csdn.net/qq_39339179/article/details/128612797,】
//分类 单页 tag 加html 伪静态
function custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . '/%pagename%.html';
$wp_rewrite->extra_permastructs['post_tag']['struct'] = 'tag/%post_tag%-1.html';
$wp_rewrite -> extra_permastructs['category']['struct'] = '/%category%-1.html';
}
add_action( 'init', 'custom_page_rules' );
//重定义分页连接 伪静态
add_filter('rewrite_rules_array','add_rewrite_rules');
function add_rewrite_rules($aRules){
$aNewRules = array(
'(.+?)-([0-9]{1,}).html$' =>'index.php?category_name=$matches[1]&paged=$matches[2]',
);
$aNewRules1 = array(
'tag/(.+?)-(\d+).html$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
);
$aRules = $aNewRules + $aRules;
$aRules = $aNewRules1 + $aRules;
return $aRules;
}
add_filter( 'redirect_canonical', 'post_custom_redirect_url');
function post_custom_redirect_url($output){
return false;
}
function native_pagenavi(){
global $wp_query, $wp_rewrite;
$wp_query->query_vars["paged"]; //当前页数
$wp_query->query_vars["category_name"]; //当前分类名
$category = '/'.$wp_query->query["category_name"];
if($wp_query->query["category_name"] == ""){
$tag = $wp_query->query_vars["tag"];
$category = '/tag/'.$tag;
}
$wp_query->query_vars["paged"] > 1 ? $current = $wp_query->query_vars["paged"] : $current = 1;
$pagination = array(
"base" => "",
"format" => "",
"total" => $wp_query->max_num_pages, //最大页数
"current" => $current,
"prev_text" => "« ",
"next_text" => " »"
);
$pagination["base"] =$category."-%#%.html";
if( !empty($wp_query->query_vars["s"]) ) {
$pagination["add_args"] = array("s"=>get_query_var("s"));
}
print_R($pagination);
echo paginate_links($pagination);
}
记得,一定要关闭 插件【WPJAM】中的【增强优化】的分类链接简化【】去掉分类目录链接中的 category。的勾,不可以选择。否则,失效!一直找不到原因,费了老大事才找到这个原因的。
进一步改进,归到一个目录下。
第二个【自己改后】测试结果:
关于我们【页面】:http://ky.hsx.ltd/a/about-us.html
文章分类【文章】:http://ky.hsx.ltd/a/product-1.html
文章分类【父级】:http://ky.hsx.ltd/a/news-1.html
文章分类【子级】:http://ky.hsx.ltd/a/news/industry-news-1.html
文章分类【孙级】:http://ky.hsx.ltd/a/news/industry-news/company-news-1.html
带分页的:
第1页:http://ky.hsx.ltd/a/news/industry-news-1.html
第2页:http://ky.hsx.ltd/a/news/industry-news-1.html/page/2
第3页:http://ky.hsx.ltd/a/news/industry-news-1.html/page/3
在主题 function.php文件最后添加:
//【改进测试【全部添加到a目录下】:WordPress全站伪静态,分别在分类列表页、列表分页、TAG标签、单页、文章页后加html后缀,https://blog.csdn.net/qq_39339179/article/details/128612797,】
//分类 单页 tag 加html 伪静态
function custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . '/a/%pagename%.html';
$wp_rewrite->extra_permastructs['post_tag']['struct'] = '/a/tag/%post_tag%-1.html';
$wp_rewrite -> extra_permastructs['category']['struct'] = '/a/%category%-1.html';
}
add_action( 'init', 'custom_page_rules' );
//重定义分页连接 伪静态
add_filter('rewrite_rules_array','add_rewrite_rules');
function add_rewrite_rules($aRules){
$aNewRules = array(
'(.+?)-([0-9]{1,}).html$' =>'index.php?category_name=$matches[1]&paged=$matches[2]',
);
$aNewRules1 = array(
'tag/(.+?)-(\d+).html$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
);
$aRules = $aNewRules + $aRules;
$aRules = $aNewRules1 + $aRules;
return $aRules;
}
add_filter( 'redirect_canonical', 'post_custom_redirect_url');
function post_custom_redirect_url($output){
return false;
}
function native_pagenavi(){
global $wp_query, $wp_rewrite;
$wp_query->query_vars["paged"]; //当前页数
$wp_query->query_vars["category_name"]; //当前分类名
$category = '/'.$wp_query->query["category_name"];
if($wp_query->query["category_name"] == ""){
$tag = $wp_query->query_vars["tag"];
$category = '/a/tag/'.$tag;
}
$wp_query->query_vars["paged"] > 1 ? $current = $wp_query->query_vars["paged"] : $current = 1;
$pagination = array(
"base" => "",
"format" => "",
"total" => $wp_query->max_num_pages, //最大页数
"current" => $current,
"prev_text" => "« ",
"next_text" => " »"
);
$pagination["base"] =$category."-%#%.html";
if( !empty($wp_query->query_vars["s"]) ) {
$pagination["add_args"] = array("s"=>get_query_var("s"));
}
print_R($pagination);
echo paginate_links($pagination);
}
记得,一定要关闭 插件【WPJAM】中的【增强优化】的分类链接简化【】去掉分类目录链接中的 category。的勾,不可以选择。否则,失效!一直找不到原因,费了老大事才找到这个原因的。
【第二个测试完毕】
最后添加: