分享一个比较少用大但是比较使用的WordPress文章内页分页函数wp_link_pages() 不是普通的文章的分页哦。

WordPress文章页面分页函数:wp_link_pages(),通过对该函数的深入了解,我们来完成对WordPress文章页面的分页。

对于一篇较为长的文章来说,单页阅读已经不再适用于她,不仅会令访客产生不适的感觉,对我们文章页面的排版也是很不友好。这时候我们急需要对文章进行分页,但WordPress默认的分页却不能令我们满意。

WordPress自身带有文章分页功能,可能该功能不被博主们常用,在默认的TinyMCE编辑器下给隐匿了。你可以尝试编辑文章时在HTML视图下插入短码<!–nextpage–>,看看你的主题有没有分页效果,没有也没关系,看了本文就知道了。WordPress v5.8.1官方正式版及必备优化代码

Share a relatively small but relatively used WordPress article page paging function wp_link_pages() is not an ordinary article paging.

Article page paging function: wp_link_pages(), through in-depth understanding of this function, we will complete the paging of article pages.

For a relatively long article, single-page reading is no longer suitable for her. It will not only make visitors feel uncomfortable, but it is also very unfriendly to the layout of our article pages. At this time, we urgently need to paginate articles, but the default pagination of WordPress cannot satisfy us.

It has an article paging function, which may not be commonly used by bloggers and is hidden under the default TinyMCE editor. You can try to insert the shortcode <!–nextpage–> in the HTML view when editing the article to see if your theme has a paging effect. It doesn’t matter if you don’t, you’ll know after reading this article.

Article paging function description Array function description: before paging navigation, you can write text, you can set the style of paging navigation to close the next page or page number next page link previous page link page number link , The specific style is not explained, DIY by yourself. Choose to use according to your needs, find the following code in the theme single.php, and paste the article pagination form of your choice below the code here.

When editing an article, insert the following article paging segment code in the HTML view to achieve article paging.

Form 1: Description: The page number loads the style of page-links through before and after Form 2: Previous page Next page Previous page&nextpagelink=Next page Description: Turn pages through the upper and lower pages, the style is bold Form 3: Previous page 1 2 3 I revised the following code on the next page and added a judgment sentence to solve the problem of code occupancy when the article is not paged. The above two groups have not been modified, please modify according to the following code.

PrevNext');} ?>Description: Up and down pages are turned in bold, and the page number is loaded with wp-pagenavi style. Follow-up: Incomplete feed output After using article paging, there will be a problem, that is, incomplete feed output, only output The first page of the article page, this will affect the reading of the rss subscribers. The solution is as follows: Find "query.php" in the "wp-includes" directory, and find the following sentence: Modify it to: More WordPress article paging related articles can be viewed: How to realize article paging without plugins How to article paging Title add page number paging page_WordPress article paging function (wp_link_pages article digital paging and page up and down)

If an article is paginated, it will greatly reduce the quick reading experience. WordPress also supports the pagination function of article content, but the wp_link_pages function it provides is a bit unfriendly.

This function provides a paging mode, which is either page up and down or digital paging. What if you want to have both up and down page and digital paging?

Put the following code in the functions.php file of the current theme: The calling method is as follows: previous page','nextpagelink' => "nextpagelink")); for the sake of beauty, you can also simply write a css style, below It is a very simple style of Zifan: If you find that your WordPress theme article or page content does not support paging, you can call it directly in this way. Of course, if you don’t need to have both digital paging and up and down pages at the same time , Then use the wp_link_pages function directly, and fill in next or number in the'next_or_number' field!

 

文章分页函数说明

<?php wp_link_pages( $args ); ?>

数组函数说明:

<?php $args = array(
‘before’ => ‘<p>’ . __(‘Pages:’),//分页导航前,可写文字,可设置样式
‘after’ => ‘</p>’,//分页导航闭合
‘link_before’ => ,
‘link_after’ => ,
‘next_or_number’ => ‘number’,//下一页还是页码
‘nextpagelink’ => __(‘Next page’),//下一页链接
‘previouspagelink’ => __(‘Previous page’),//上一页链接
‘pagelink’ => ‘%’,//页码链接
‘more_file’ => ,
‘echo‘ => 1 ); ?>

如何实现文章分页

文章分页的形式我们举例说明三种,具体样式不做说明,自己DIY。根据自己的需要选择使用,在主题single.php中找到以下代码,在此处代码的下面粘贴上你选择的文章分页形式。

<?php the_content(); ?>

编辑文章时在HTML视图下插入以下文章分页段码即可实现文章分页。

<!–nextpage–>

形式一:page 1 2 3

<?php wp_link_pages(‘before=<div id=”page-links>&after=</div>&next_or_number=number&pagelink=page %’); ?>

说明:页码通过before和after加载page-links的样式

形式二:上一页 下一页

<?php wp_link_pages(‘before=<strong>&after=</strong>&next_or_number=next&previouspagelink=上一页&nextpagelink=下一页’); ?>

说明:通过上下页翻页,样式加粗

形式三:上一页 1 2 3 下一页

以下代码我进行了重新修订,加入了判断句,解决了文章没有分页时代码占位的情况。以上两组没做修改,请根据以下代码修改。

<?php if ( $numpages > ‘1’ ) {
wp_link_pages(‘before=<strong>&after=</strong>&next_or_number=next&previouspagelink=上一页&nextpagelink=&nbsp’);
wp_link_pages(‘before=<span class=“wp-pagenavi”>&after=</span>&next_or_number=number’);
echo “&nbsp;”;
wp_link_pages(‘before=<strong>&after=</strong>&next_or_number=next&previouspagelink=&nbsp&nextpagelink=下一页’);
} ?>

说明:上下页翻页加粗,页码加载wp-pagenavi样式

后续:feed输出不全

在使用文章分页后会出现一个问题,就是feed输出不全,仅会输出文章页面第一页,这样会影响通过rss订阅者的阅读。解决方法如下:

找到“wp-includes”目录下的“query.php”,查找到以下的语句:
if ( strpos( $content, ‘<!–nextpage–>’ ) ) {

将其修改为:
if ( strpos( $content, ‘<!–nextpage–>’ ) && ( !is_feed() ) ) {

更多WordPress文章分页相关文章可查看:

WordPress无插件如何实现文章分页

wordpress文章分页如何为标题添加页码

 

分页page_WordPress文章分页功能(wp_link_pages文章数字分页与上下翻页)

 

一篇文章如果被分页,将会大大的降低了快速阅读的体验,WordPress 也是支持文章内容的分页功能,但是其提供的 wp_link_pages 函数却有点不友好。

WordPress wp_link_pages 这个函数提供了分页模式,要么是上下翻页,要么就是数字分页,如果想要既有上下翻页,又有数字分页该怎么办呢?

将以下代码放在当前主题的 functions.php 文件中:

调用方式如下:
','after' => '
','next_or_number' => 'next_and_number', 'link_before' => '','link_after' => '','previouspagelink' => '上一页','nextpagelink' => "下一页"));

为了美观,大家还可以简单的写个 css 样式,下面是子凡的一个非常简单的样式:

如果你发现你的 WordPress 主题文章或者页面内容不支持分页,那么可以通过这样的一个方式方法直接调用啦,当然如果你不需要同时拥有数字分页和上下翻页,那么直接使用 wp_link_pages 函数,'next_or_number'字段填写 next 或 number 就可以啦!

 

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。