最近有用户提出自己文章内容很长,而WordPress主题没设置侧边栏随动,导致页面排版很难看,咨询是否可以设置分页,今天小编就分享一下实现文章内容分页WordPress函数wp_link_pages教程,它能将一篇长文章分成几个页面来显示,实现文章内容分页,这样就不会影响到网页的排版。

函数位于wp-includes/post-template.php文件中,由于内容太多,所以这里就不贴源码了。

函数用法

<?php wp_link_pages( $args ); ?>

参数说明

<?php

$args = array(

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’before\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'<p>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ . __( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’Pages:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’twentyfourteen\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ),

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’after\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'</p>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’link_before\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’link_after\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’next_or_number\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’number\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’separator\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’nextpagelink\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => __( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’Next page\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’twentyfourteen\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’),

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’previouspagelink\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => __( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’Previous page\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’twentyfourteen\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ),

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’pagelink\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’%\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’echo\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => 1

);

?>

before – 字符串。所有链接之前的文本,默认值<p>Pages:(通常和after搭配使用)

after – 字符串。所有链接之后的文本,默认值</p>(通常和before搭配使用)

link_before – 字符串。单个链接文本之前的文本,默认为空

link_after – 字符串。单个链接文本之后的文本,默认为空

next_or_number – 字符串。选择使用数字分页还是上一页、下一页文本分页,可选number或next,默认number

separator – 字符串。页码分隔符,默认似乎是空格

nextpagelink – 字符串。下一页链接文本,默认Next page

previouspagelink – 字符串。上一页链接文本,默认Previous page

pagelink – 字符串。页码的字符串格式,百分号%会被替换成数字,如页%会生成 “页1”、“页2”这样的样式

echo – 布尔型。选择是要返回结果还是直接输出,默认为True,返回NULL或返回内容;设置为false,则直接输出HTML格式

使用实例

1、全部使用默认值,下一页、上一页使用段落标签,Page 1,Page 2作为分页页码:

<?php wp_link_pages();?>

2、使用段落标签包围分页链接

<?php wp_link_pages(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’before=<p>&after=</p>&next_or_number=number&pagelink=page %\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);?>

3、使用div包围分页链接,便于CSS样式修改

<?php wp_link_pages(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’before=<div id=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”page-links\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>&after=</div>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);?>

提示:可以CSS中对#page-links进入样式修改

分页方法

在文章内容页模板single.php中找到输出文章内容的WordPress函数the_content,然后在下面添加一行代码:

<?php wp_link_pages(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’before=<div id=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”page-links\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>&after=</div>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);?>

然后在后台编辑文章时,在你需要分页的地方使用

<!–nextpage–>

注意:这段分页代码必须在文本模式下使用,或者直接开启快捷按钮,点击按钮即可增加分页。

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部