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(向指定的表添加索引)
202 0
|
数据安全/隐私保护
云虚拟主机wordpress发送邮件,解决25端口和fsockopen函数问题
最近在阿里云的云虚拟主机上用wordpress搭建了一个站点,搭建好之后发现无法发送邮件。 通过查资料发现云虚拟主机默认封锁了25端口,于是尝试使用第三方SMTP通过465端口发送,wordpress中有现有的插件,安装了使用人数最多的WP Mail SMTP,在插件的设置中填好各项信息,邮件程序选择“其他SMTP”,SMTP端口填465,加密选SSL/TLS,其他信息可在邮件服务商(如阿里云邮件服务、QQ邮箱、163邮箱等)的设置中找到(注意密码可能并非邮箱登录密码而是另外的授权码)。
3639 1
|
PHP 数据安全/隐私保护 数据库
|
SQL 缓存 数据库
wordpress 常用函数-wpdb类
与数据库建立接口 WordPress为用户提供了一系列用于数据库操作的函数类——wpdb。Wpdb类建立在Justin Vincent编写并维护的ezSQL类的基础上。 使用须知 不可直接调用wpdb类中的方法,应使用全局变量$wpdb。
1319 0

相关实验场景

更多