wordpress 导航相关的函数

简介: 上一篇文章、下一篇文章previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' );ne...

上一篇文章、下一篇文章

previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' );
next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' );

看函数名称知道,这两个方法都是生成一个链接。format 指的是链接格式,link指的是链接显示的文本,in_same_term 表示是否与当前文章在同一分类下, excluded_terms 表示排队在外的分类,taxonomy 是基于in_same_term的。

前后结合

the_post_navigation( array(
                'prev_text'                  => __( '上一篇: %title' ),
                'next_text'                  => __( '下一篇: %title' ),
                'screen_reader_text' => ( '自定义标题' )
            ));

上一页、下一页

<?php 
previous_posts_link( $label = null );
next_posts_link( $label = null, $max_page = 0 );
 ?>

你会发现上一页、下一页 方法名与 上一篇文章、下一篇文章只是一个s字母的差别,而参数更简洁了,可自定义的内容更少了些。当然这里不能叫next_page_link,因为page是页面的意思,不是分页的意思。文章按发布时间有新旧之分,前一页呢是看较新的文章,后一页呢是较早前文章,而max_page这个参数是指定你可以看多旧,所以,上一页没有这个参数。

文章分页导航 the_posts_pagination

参数

  • mid_size (int) - How many page numbers to display to either side of the current page. Defaults to 1.
  • prev_text (string) - Text of the link to the next set of posts. Defaults to “Previous”.
  • next_text (string) - Text of the link to the next set of posts. Defaults to “Next”.
  • screen_reader_text (string) - Text meant for screen readers. Defaults to “Posts navigation”.

参考资料

https://mor10.com/add-proper-pagination-default-wordpress-themes/

相关文章
|
数据库 索引
WordPress 功能函数—— add_clean_index(向指定的表添加索引)
WordPress 功能函数—— add_clean_index(向指定的表添加索引)
79 0
|
数据安全/隐私保护
云虚拟主机wordpress发送邮件,解决25端口和fsockopen函数问题
最近在阿里云的云虚拟主机上用wordpress搭建了一个站点,搭建好之后发现无法发送邮件。 通过查资料发现云虚拟主机默认封锁了25端口,于是尝试使用第三方SMTP通过465端口发送,wordpress中有现有的插件,安装了使用人数最多的WP Mail SMTP,在插件的设置中填好各项信息,邮件程序选择“其他SMTP”,SMTP端口填465,加密选SSL/TLS,其他信息可在邮件服务商(如阿里云邮件服务、QQ邮箱、163邮箱等)的设置中找到(注意密码可能并非邮箱登录密码而是另外的授权码)。
3297 1
|
PHP 数据安全/隐私保护 数据库
|
PHP
WordPress函数query_posts用法汇总
最近经常有网友跟我咨询WordPress函数query_posts的相关用法,说起来query_posts实在是太强大,参数无数,用法更是无数,如果让我说它的用法,我根本没法一一说清楚。开始之前,你可以先看看query_posts的官方文档,query_posts的全部参数可以参考:WP_Query。
1307 0
|
JavaScript PHP 前端开发
WordPress路径相关函数总结
与WordPress打交道,经常遇到的一个问题就是获取路径,包括URL路径和服务器路径,在主题或插件中引用js或css文件需要URL地址,而include一些文件时则需要服务器路径。在WordPress中,不能认定wp-content目录一定位于/wp-content下,也不能认为admin的地址一定是/wp-admin,为了避免错误,了解WordPress中与获取路径相关的函数很重要。
962 0