函数文档

the_posts_pagination()

💡 云策文档标注

概述

the_posts_pagination() 是 WordPress 中用于显示文章分页导航的函数,适用于归档页面。它基于 get_the_posts_pagination() 实现,通过参数数组自定义分页链接的样式和行为。

关键要点

  • 函数用于输出分页导航,支持自定义参数如格式、文本和链接结构。
  • 参数 $args 可选,详细选项参考 get_the_posts_pagination(),包括 base、format、total、current 等。
  • 默认参数为 array(),函数内部调用 get_the_posts_pagination() 并直接输出结果。
  • 相关函数 get_the_posts_pagination() 用于检索分页导航,位于 wp-includes/link-template.php。
  • 自 WordPress 4.1.0 版本引入,无后续变更记录。

代码示例

// 显示带额外页面链接的分页
the_posts_pagination( array(
    'mid_size' => 2
) );

// 显示带自定义上一页/下一页文本的分页
the_posts_pagination( array(
    'mid_size' => 2,
    'prev_text' => __( 'Back', 'textdomain' ),
    'next_text' => __( 'Onward', 'textdomain' ),
) );

📄 原文内容

Displays a paginated navigation to next/previous set of posts, when applicable.

Parameters

$argsarrayoptional
See get_the_posts_pagination() for available arguments.

More Arguments from get_the_posts_pagination( … $args )

Array or string of arguments for generating paginated links for archives.

  • base string
    Base of the paginated url. Default empty.
  • format string
    Format for the pagination structure. Default empty.
  • total int
    The total amount of pages. Default is the value WP_Query‘s max_num_pages or 1.
  • current int
    The current page number. Default is 'paged' query var or 1.
  • aria_current string
    The value for the aria-current attribute. Possible values are 'page', 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
  • show_all bool
    Whether to show all pages. Default false.
  • end_size int
    How many numbers on either the start and the end list edges.
    Default 1.
  • mid_size int
    How many numbers to either side of the current pages. Default 2.
  • prev_next bool
    Whether to include the previous and next links in the list. Default true.
  • prev_text string
    The previous page text. Default ‘« Previous’.
  • next_text string
    The next page text. Default ‘Next »’.
  • type string
    Controls format of the returned value. Possible values are 'plain', 'array' and 'list'. Default is 'plain'.
  • add_args array
    An array of query args to add. Default false.
  • add_fragment string
    A string to append to each link. Default empty.
  • before_page_number string
    A string to appear before the page number. Default empty.
  • after_page_number string
    A string to append after the page number. Default empty.

Default:array()

Source

function the_posts_pagination( $args = array() ) {
	echo get_the_posts_pagination( $args );
}

Changelog

Version Description
4.1.0 Introduced.

User Contributed Notes