wp_page_menu_args
云策文档标注
概述
wp_page_menu_args 是一个 WordPress 过滤器钩子,用于修改生成基于页面的菜单时使用的参数。它允许开发者自定义页面菜单的显示方式,如排序、包含或排除特定页面等。
关键要点
- 过滤器钩子名称:wp_page_menu_args,用于过滤 wp_page_menu() 函数的参数数组。
- 参数 $args 是一个数组,包含多个选项,如 child_of、sort_order、sort_column、hierarchical、exclude、include、meta_key、meta_value、authors、parent、exclude_tree、number、offset、post_type 和 post_status。
- 这些参数控制页面查询的行为,例如按层级显示、排序方式、排除特定页面或基于元数据筛选。
- 使用示例:通过 apply_filters('wp_page_menu_args', $args) 应用过滤器,开发者可以修改 $args 数组以定制菜单输出。
代码示例
$args = apply_filters( 'wp_page_menu_args', $args );注意事项
- 参数 $include 不能与 $child_of、$parent、$exclude、$meta_key、$meta_value 或 $hierarchical 同时使用。
- $meta_value 需要与 $meta_key 一起使用才能生效。
- $offset 参数仅在设置了 $number 参数时有效。
- 默认情况下,post_type 为 'page',post_status 为 'publish',但可以通过过滤器修改。
原文内容
Filters the arguments used to generate a page-based menu.
Description
See also
Parameters
$argsarray-
An array of page menu arguments. See wp_page_menu() for information on accepted arguments.
More Arguments from wp_page_menu( … $args )
Array or string of arguments to retrieve pages.
child_ofintPage ID to return child and grandchild pages of. Note: The value of$hierarchicalhas no bearing on whether$child_ofreturns hierarchical results. Default 0, or no restriction.sort_orderstringHow to sort retrieved pages. Accepts'ASC','DESC'. Default'ASC'.sort_columnstringWhat 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'.hierarchicalboolWhether to return pages hierarchically. If false in conjunction with$child_ofalso being false, both arguments will be disregarded.
Default true.excludeint[]Array of page IDs to exclude.includeint[]Array of page IDs to include. Cannot be used with$child_of,$parent,$exclude,$meta_key,$meta_value, or$hierarchical.meta_keystringOnly include pages with this meta key.meta_valuestringOnly include pages with this meta value. Requires$meta_key.authorsstringA comma-separated list of author IDs.parentintPage ID to return direct children of. Default -1, or no restriction.exclude_treestring|int[]Comma-separated string or array of page IDs to exclude.numberintThe number of pages to return. Default 0, or all pages.offsetintThe number of pages to skip before returning. Requires$number.
Default 0.post_typestringThe post type to query. Default'page'.post_statusstring|arrayA comma-separated list or array of post statuses to include.
Default'publish'.
Source
$args = apply_filters( 'wp_page_menu_args', $args );
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |