钩子文档

the_posts_pagination_args

💡 云策文档标注

概述

the_posts_pagination_args 是一个 WordPress 过滤器钩子,用于修改文章分页链接的参数。它允许开发者自定义分页导航的显示和行为,基于 paginate_links() 函数的参数。

关键要点

  • 过滤器钩子:the_posts_pagination_args,用于过滤文章分页链接的参数。
  • 参数结构:接受一个数组参数 $args,包含分页链接的各种设置,如屏幕阅读器文本、ARIA 标签、类名等。
  • 扩展参数:继承自 paginate_links() 函数,支持 base、format、total、current、aria_current、show_all、end_size、mid_size、prev_next、prev_text、next_text、type、add_args、add_fragment、before_page_number、after_page_number 等。
  • 相关函数:与 get_the_posts_pagination() 函数关联,用于生成分页导航。
  • 版本历史:从 WordPress 6.1.0 版本引入。

代码示例

$args = apply_filters( 'the_posts_pagination_args', $args );

📄 原文内容

Filters the arguments for posts pagination links.

Parameters

$argsarray
Default pagination arguments, see paginate_links() .

  • screen_reader_text string
    Screen reader text for navigation element.
    Default ‘Posts navigation’.
  • aria_label string
    ARIA label text for the nav element. Default 'Posts'.
  • class string
    Custom class for the nav element. Default 'pagination'.

More Arguments from paginate_links( … $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.

Source

$args = apply_filters( 'the_posts_pagination_args', $args );

Changelog

Version Description
6.1.0 Introduced.