WordPress的TwentySixteen主题,免插件实现分多页的功能

技术流1 8,285阅读模式

很多人提到了WP的那个Page-Navi插件不好用了(实际上已经不好用很久了,因为这个插件一直没有更新,但是WP几乎每个月都会更新出新版本),在Wordpress的4.1版本之后的版本都提供了自动分页的功能,但是这个分页功能也有一个硬伤,那就是只有第一页和第二页,外加最后一页,如果你文章多,想跳到第45页,那么你就翻把(当然你可以在浏览器地址栏输入,不过大家基本都不知道这条)。

这里提供了一个办法,把分页给分到10页以上(或者任意你想要的页码),这个方需要需要修改一下代码,具体方法如下:文章源自原紫番博客-https://www.yuanzifan.com/6094.html

打开Index.php页面文章源自原紫番博客-https://www.yuanzifan.com/6094.html

在其中找到这段代码:

the_posts_pagination( array(
'prev_text' => __( 'Previous page', 'twentysixteen' ),
'next_text' => __( 'Next page', 'twentysixteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>',
文章源自原紫番博客-https://www.yuanzifan.com/6094.html

上面这段代码是一个函数the_posts_pagination,这个函数的默认是分页是2.你需要在下面添加一行代码,然后点击保存,那么这行代码就可以让你的博客页面分成10页显示(具体效果可参看本站首页的分页效果)

the_posts_pagination( array(
'mid_size' => 10,
'prev_text' => __( 'Previous page', 'twentysixteen' ),
'next_text' => __( 'Next page', 'twentysixteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>',
文章源自原紫番博客-https://www.yuanzifan.com/6094.html

 文章源自原紫番博客-https://www.yuanzifan.com/6094.html 文章源自原紫番博客-https://www.yuanzifan.com/6094.html

 最后更新:2016-6-10
    • 懿古今 0

      够用就行了,懒得研究这么多了

    发表评论

    匿名网友
    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
    确定

    拖动滑块以完成验证