post_class

最后更新于:2021-11-27 16:05:27

apply_filters( ‘post_class’, string[] $classes, string[] $class, int $post_id )

Filters the list of CSS class names for the current post.

参数

$classes

(string[])
An array of post class names.

$class

(string[])
An array of additional class names added to the post.

$post_id

(int)
The post ID.

源文件

文件: gc-includes/post-template.php

View on Trac

add_filter('post_class', 'set_row_post_class', 10,3);
function set_row_post_class($classes, $class, $post_id){
    if (!is_admin()) { //make sure we are in the dashboard 
        return $classes;
    }
    $screen = get_current_screen(); //verify which page we're on
    if ('my-custom-type' != $screen->post_type && 'edit' != $screen->base) {
        return $classes;
    }
    //check if some meta field is set 
    $profile_incomplete = get_post_meta($post_id, 'profile_incomplete', true);
    if ('yes' == $profile_incomplete) {
        $classes[] = 'profile_incomplete'; //add a custom class to highlight this row in the table
    }

    // 响应 the array
    return $classes;
}