钩子文档

wp_list_pages

💡 云策文档标注

概述

wp_list_pages 是一个 WordPress 过滤器,用于修改页面列表的 HTML 输出。它允许开发者自定义页面列表的呈现方式,通过传递参数控制页面查询和排序。

关键要点

  • 过滤器名称:wp_list_pages,用于过滤页面列表的 HTML 输出。
  • 参数:$output(HTML 输出字符串)、$parsed_args(页面列表参数数组)、$pages(页面对象数组)。
  • 参数详解:包括 child_of、sort_order、sort_column、hierarchical、exclude、include、meta_key、meta_value、authors、parent、exclude_tree、number、offset、post_type、post_status 等,用于精确控制页面查询和显示。
  • 相关函数:wp_list_pages(),用于检索或显示页面列表。
  • 变更历史:从 1.5.1 版本引入,4.4.0 版本添加了 $pages 参数。

📄 原文内容

Filters the HTML output of the pages to list.

Description

See also

Parameters

$outputstring
HTML output of the pages list.
$parsed_argsarray
An array of page-listing arguments. See wp_list_pages() for information on accepted arguments.

More Arguments from wp_list_pages( … $args )

Array or string of arguments to retrieve pages.

  • child_of int
    Page ID to return child and grandchild pages of. Note: The value of $hierarchical has no bearing on whether $child_of returns hierarchical results. Default 0, or no restriction.
  • sort_order string
    How to sort retrieved pages. Accepts 'ASC', 'DESC'. Default 'ASC'.
  • sort_column string
    What columns to sort pages by, comma-separated. Accepts 'post_author', 'post_date', 'post_title', 'post_name', 'post_modified', 'menu_order', 'post_modified_gmt', 'post_parent', 'ID', 'rand', 'comment*count'.
    'post*' can be omitted for any values that start with it.
    Default 'post_title'.
  • hierarchical bool
    Whether to return pages hierarchically. If false in conjunction with $child_of also being false, both arguments will be disregarded.
    Default true.
  • exclude int[]
    Array of page IDs to exclude.
  • include int[]
    Array of page IDs to include. Cannot be used with $child_of, $parent, $exclude, $meta_key, $meta_value, or $hierarchical.
  • meta_key string
    Only include pages with this meta key.
  • meta_value string
    Only include pages with this meta value. Requires $meta_key.
  • authors string
    A comma-separated list of author IDs.
  • parent int
    Page ID to return direct children of. Default -1, or no restriction.
  • exclude_tree string|int[]
    Comma-separated string or array of page IDs to exclude.
  • number int
    The number of pages to return. Default 0, or all pages.
  • offset int
    The number of pages to skip before returning. Requires $number.
    Default 0.
  • post_type string
    The post type to query. Default 'page'.
  • post_status string|array
    A comma-separated list or array of post statuses to include.
    Default 'publish'.

$pagesWP_Post[]
Array of the page objects.

Source

$html = apply_filters( 'wp_list_pages', $output, $parsed_args, $pages );

Changelog

Version Description
4.4.0 $pages added as arguments.
1.5.1 Introduced.