钩子文档

manage_pages_columns

💡 云策文档标注

概述

manage_pages_columns 是一个 WordPress 过滤器钩子,用于自定义页面列表表格中显示的列。它允许开发者通过修改关联数组来添加、移除或重排列标题。

关键要点

  • 过滤器钩子:manage_pages_columns,应用于页面管理屏幕的列列表。
  • 参数:$posts_columns,一个关联数组,键为列名,值为列标题文本。
  • 相关钩子:与 manage_pages_custom_column 动作钩子配合使用,用于自定义每列的内容。
  • 内置列类型:包括 cb(复选框)、title(标题,含编辑链接)、author(作者)、categories(分类)、tags(标签)、comments(评论数)、date(日期和发布状态)等。
  • 默认显示:页面类型支持的所有列。

代码示例

add_filter( 'manage_pages_columns', 'my_custom_pages_columns' );

function my_custom_pages_columns( $columns ) {

    /** Add a Thumbnail Column **/
    $myCustomColumns = array(
        'thumbnail' => __( 'Thumbnail', 'Aternus' )
    );
    $columns = array_merge( $columns, $myCustomColumns );

    /** Remove a Author, Comments Columns **/
    unset(
        $columns['author'],
        $columns['comments']
    );

    return $columns;
}

📄 原文内容

Filters the columns displayed in the Pages list table.

Parameters

$posts_columnsstring[]
An associative array of column headings.

More Information

  • Applied to the list of columns to print on the manage Pages Screen. Filter function argument/return value is an associative array where the element key is the name of the column, and the value is the header text for that column.
  • See also the action hook manage_pages_custom_column, which alters the column information for each page in the edit table.

Built-in Column Types

Note: Listed in order of appearance. By default, all columns supported by the post type are shown.

  • cb Checkbox for bulk actions.
  • title
    Post title.

    Includes “edit”, “quick edit”, “trash” and “view” links. If $mode (set from $_REQUEST['mode']) is ‘excerpt’, a post excerpt is included between the title and links.

  • author Post author.
  • author Post author.
  • categories Categories the post belongs to.
  • tags Tags for the post.
  • comments Number of pending comments.
  • date The date and publish status of the post.

Source

$posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );

Changelog

Version Description
2.5.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Example migrated from Codex:

    The example below adds a “Thumbnail” column, then removes an “Author” column and a “Comments” Column.

    add_filter( 'manage_pages_columns', 'my_custom_pages_columns' );
    
    function my_custom_pages_columns( $columns ) {
    
    	/** Add a Thumbnail Column **/
    	$myCustomColumns = array(
    		'thumbnail' => __( 'Thumbnail', 'Aternus' )
    	);
    	$columns = array_merge( $columns, $myCustomColumns );
    
    	/** Remove a Author, Comments Columns **/
    	unset(
    		$columns['author'],
    		$columns['comments']
    	);
    
    	return $columns;
    }