manage_posts_columns

最后更新于:2021-11-27 06:04:31

apply_filters( ‘manage_posts_columns’, string[] $post_columns, string $post_type )

Filters the columns displayed in the Posts list table.

参数

$post_columns

(string[])
An associative array of column headings.

$post_type

(string)
The post type slug.

源文件

文件: gc-admin/includes/class-gc-posts-list-table.php

View on Trac

<?php
namespace DemoPlugin;

const COLUMN_ID = 'publisher';

/**
 * Register the custom column.
 *
 * @param array $columns Existing columns.
 * @return array Columns with custom column added.
 */
function register_column( array $columns ) : array {
	$columns[ COLUMN_ID ] = __( 'Publisher', 'demo-plugin' );
	return $columns;
}
add_action( 'manage_posts_columns', __NAMESPACE__ . '\register_column' );

// You will likely also want to hook into 'manage_posts_custom_column' to
// output the column's value.
function render_column( string $column_id ) {
	if ( $column_id !== COLUMN_ID ) {
		return;
	}

	$post = get_post();
	echo esc_html( get_post_meta( $post->ID, '_demo_publisher', true ) );
}
add_action( 'manage_posts_custom_column',  __NAMESPACE__ . '\render_column' );

function gcdocs_posts_thumb_columns( $columns ) {
    $post_new_columns = array(
       'post_thumbs' => esc_html__( 'Thumbs', 'text_domain' ),
    );
    return array_merge( $columns, $post_new_columns );
}
add_filter( 'manage_posts_columns', 'gcdocs_posts_thumb_columns', 5 );

function gcdocs_posts_custom_columns( $column_name, $id ) {
    if ( 'post_thumbs' === $column_name ) {
        the_post_thumbnail( 'thumbnail' );
    }
}
add_action( 'manage_posts_custom_column', 'gcdocs_posts_custom_columns', 5, 2 );