php 分页 url重写 分页问题,解决千古难题,wordpress分页URL问题,wordpress给分页加链接...

原本的wordpress文章如果分页会成如下的结构:

http://www.xyqzmt.cn/1.html/2

通常固定链接都是这样的结构,设为/%postname%.html或者/%post_id%.html 以前我一直无法解决如上的问题,最后放弃挣扎,如果遇到很长的文章全都放在一个页面里面。

95736fc0487abd81535ff7854580ea61.png

今天在知更鸟大佬的博客上找到了结局办法。http://zmingcx.com/pseudo-static-article-page-links.html

将下面代码添加到当前主题 functions.php中:

本文提供一下/%post_id%.html的修改方法。

// 适合/%post_id%.html分页链接修正

class Rewrite_Inner_Page_Links_id{

var $separator;

function __construct(){

$this->separator = ‘/page-‘;

if( !is_admin() || defined( ‘DOING_AJAX’ ) ) :

add_filter( ‘wp_link_pages_link’, array( $this, ‘inner_page_link_format’ ), 10, 2 );

add_filter( ‘get_comments_pagenum_link’, array( $this, ‘comment_page_link_format’ ) );

add_filter( ‘redirect_canonical’, array( $this, ‘cancel_redirect_for_paged_posts’ ), 10, 2 );

endif;

if( is_admin() ) :

add_filter( ‘rewrite_rules_array’, array( $this, ‘pagelink_rewrite_rules’ ) );

register_activation_hook( __FILE__, array( $this, ‘flush_rewrite_rules’ ) ) ;

register_deactivation_hook( __FILE__, array( $this, ‘flush_rewrite_rules’ ) );

endif;

}

function flush_rewrite_rules(){

flush_rewrite_rules();

}

// 修改post分页链接的格式

function inner_page_link_format( $link, $number ){

if( $number > 1 ){

if( preg_match( ‘%

$link = preg_replace( “%(\.html)/(\d*)%”, $this->separator.”$2$1″, $link );

}

}

return $link;

}

// 为新的链接格式增加重定向规则,移除原始分页链接的重定向规则,防止重复收录

function pagelink_rewrite_rules( $rules ){

foreach ($rules as $rule => $rewrite) {

if ( $rule == ‘([0-9]+).html(/[0-9]+)?/?$’ ) {

unset($rules[$rule]);

}

}

$new_rule[‘([0-9]+)(‘.$this->separator.'([0-9]+))?.html/?$’] = ‘index.php?p=$matches[1]&page=$matches[3]’;

return $new_rule + $rules;

}

// 禁止WordPress将页面分页链接跳转到原来的格式

function cancel_redirect_for_paged_posts( $redirect_url, $requested_url ){

global $wp_query;

if( is_single() && $wp_query->get( ‘page’ ) > 1 ){

return false;

}

return true;

}

}

new Rewrite_Inner_Page_Links_id();

提示:添加代码后,需要保存一下固定链接设置。

之后再次打开文章分页链接,会变成类似的:

/morning-paper-news/page-2.html

/132/page-2.html

解决了我的千古难题,我弄的那个漫画教程网站,复制贴吧里面的教程,有大量的图片,起码要分个七八页才OK的。增加网站的PV也挺好的!前提就是内容足够吸引人!等有机会再研究那种能整页展示分页的功能。(参考太平洋电脑网上的那种)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440771.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【POJ - 2378】Tree Cutting(树形dp,树的重心变形)

题干&#xff1a; After Farmer John realized that Bessie had installed a "tree-shaped" network among his N (1 < N < 10,000) barns at an incredible cost, he sued Bessie to mitigate his losses. Bessie, feeling vindictive, decided to sabotage…

php 5.5.38 ldap安装,centos5.5系统下面,lnmp环境下面php加载ldap扩展

对于LDAP的安装得先安装检查下面是不是已经安装&#xff0c;如果没有安装之&#xff1a;检查&#xff1a;yum list openldapyum list openldap-devel安装 &#xff1a;yum install openldapyum install openldap-devel一定要执行这条命令&#xff1a;cp -frp /usr/lib64/liblda…

【牛客 - 181F】子序列(容斥,组合数,费马小定理)

题干&#xff1a; 题目描述 给出一个长度为n的序列&#xff0c;你需要计算出所有长度为k的子序列中&#xff0c;除最大最小数之外所有数的乘积相乘的结果 输入描述: 第一行一个整数T&#xff0c;表示数据组数。 对于每组数据&#xff0c;第一行两个整数N&#xff0c;k&#…

php石头剪刀布五局三胜,求程序,下面是剪刀石头布的程序,谁能帮忙改成能选择三局两胜,五局三胜……的?能成功运行的加分...

// 只需要修改main() //#define AllCount 5 // 输入你要选择的赛制&#xff0c;5为五局三胜&#xff0c;3为三局两胜 //#define WinCount AllCount / 2 1 void main() { Play play; int a5; int failure0,win0,tie0; unsigned long begin; int WinCount; int AllCount; printf…

【CodeForces - 1102C 】Doors Breaking and Repairing (思维,简单博弈)

题干&#xff1a; You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move. There are nn doors, the i…

php如何提高程序运行效率,如何提高PHP的运行效率 | 萧小寒

摘要在网站开发的过程中&#xff0c;如果我们不太注意代码的规范和编写技巧&#xff0c;很容易导致代码运行效率低下的问题。这个问题应该是绝大多数程序员身上的通病。如何编写出高效的代码&#xff0c;成为很多初中级程序员向高级程序员转变的一道无法逾越的坎。今天让我们一…

【CodeForces - 485C】Bits (二进制相关,数学,贪心)

题干&#xff1a; Lets denote as the number of bits set (1 bits) in the binary representation of the non-negative integer x. You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, an…

php工程导致系统蓝屏,经常蓝屏是什么原因

经常蓝屏的原因&#xff1a;1、错误安装或更新显卡驱动后导致电脑蓝屏&#xff1b;2、超频过度是导致蓝屏&#xff1b;3、安装的软件存在不兼容&#xff1b;4、电脑内部硬件温度过高&#xff1b;5、内存条接触不良或内存损坏。错误更新显卡驱动错误安装或更新显卡驱动后导致电脑…

【CodeForces - 485B】Valuable Resources (贪心,水题,几何相关)

题干&#xff1a; Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Lets suppose that your task is to build a square city. The world map uses the Car…

php测试插入,php – 使用Symfony测试数据库插入

今天是个好日子,在过去的几天里,我一直在研究测试驱动开发,并决定我也需要学习它.虽然我无法弄清楚如何准确地做到这一点.我的项目依赖于Symfony2.1.6框架和Doctrine,所以我有一些需要填充的数据库表.Book (1,n) – (0,n) Genre现在,如果我想插入一个类型记录,我首先需要编写一…

【CodeForces - 485A】Factory (水题,抽屉原理,tricks)

题干&#xff1a; One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to p…

matlab调用哈希表,ros与matlab联动使用

ros与matlab联动使用联动使用教程1 ubuntu18.04或16.04下安装matlab R2017b参考链接2 ubuntu下基于matlab启动rosmatlab中常用命令如下&#xff1a;查看robotics system toolbox工具箱是否安装成功help robotics.rosrosinit ——表示启动ROS&#xff0c;相当于roscorerosshutdo…

【CodeForces - 1020C】Elections (枚举投票数,贪心)

题干&#xff1a; As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know th…

java 制作快捷键,Java快捷键制作

Java快捷键制作用过VB的知道按下F5是运行窗体&#xff0c;用过Photoshop的知道按下Tab是隐藏所有面板&#xff0c;你的Java程序也想有这个功能么&#xff1f;那么希望这篇文章对您有所帮助。子菜单类JMenuItem有一个方法不知道你注意过没有:setAccelerator。打开帮助文件对这个…

【CodeForces - 1020A】New Building for SIS(模拟)

题干&#xff1a; You are looking at the floor plan of the Summer Informatics Schools new building. You were tasked with SIS logistics, so you really care about travel time between different locations: it is important to know how long it would take to get …

matlab 实验5,MATLAB实验5报告.doc

实验课程名称&#xff1a;《数学软件与数学实验》实验项目名称实验五&#xff1a;线性规划问题求解实验成绩实 验 者王宗德专业班级数学1504组 别同组者实验日期16年5月一、实验目的1. 掌握用MATLAB优化工具箱求解线性规划问题的方法&#xff1b;2. 练习建立实际问题的线性规划…

【CodeForces - 1020B】Badge(模拟,图,环)

题干&#xff1a; In Summer Informatics School, if a student doesnt behave well, teachers make a hole in his badge. And today one of the teachers caught a group of nn students doing yet another trick. Lets assume that all these students are numbered from …

Matlab样条拟合曲面,样条曲面拟合及其Matlab实现

1符号和定义先讨论一元情形,给定区间[a,b]的一个分划,ax00,x(xi,xik)0,x[xi,xik],i-k1,…,n-1(iii)若xjixijh,则Ni,k(x)k(x-xih-k12)其中k(x)k1j0(-1)jCjk1(xk12-j)k/k!为以xjj-k12(j0,1,…,k1)为结点的k次等距B样条.Ni,k(x)的其他性质参见[1,2,3,4]满足(3)的k次样条插值曲线s(…

【Hihocoder - 1723】子树统计(线性基合并)

题干&#xff1a; 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一棵N个节点的有根树&#xff0c;树上每个节点有一个非负整数权重Wi。定义节点集合S{i1, i2, ……, ir}的总权重为&#xff1a;(⊕是异或运算) 每次询问一棵子树内所有可能出现的总权重数量&a…

php postgresql多条,PHPPostgreSQL函数列表 - phpStudy

echo $r["fun"]. .$r["title"]; ?>PostgreSQL函数列表pg_close - 关闭一个 PostgreSQL 连接pg_connect - 打开一个 PostgreSQL 连接pg_convert - 将关联的数组值转换为适合 SQL 语句的格式。pg_copy_from - 根据数组将记录插入表中pg_copy_to - 将一个…