如果您想使用PHP解决方案,那么post_class
过滤器挂钩(codex) 将允许您这样做-请参见下面的示例。可以将其粘贴到函数中。php。
请注意,从帖子列表中隐藏帖子并不会限制其访问,用户仍然可以直接使用帖子的编辑url访问编辑屏幕或使用顶部管理栏中的链接。
function set_admin_post_class( $classes, $class, $post_id ) {
// affect post classes only in dashboard context
if ( ! is_admin() ) {
return $classes;
}
// Figure out where in dashboard we actually are
// This will return early if we are not currently editing "pages"
$screen = get_current_screen();
if ( empty( $screen->post_type ) || \'page\' !== $screen->post_type || \'edit\' !== $screen->base ) {
return $classes;
}
// Now let\'s get list of all items from admin menu
global $menu;
// $menu is an array of arrays, label comes always first in every element
$menu_labels = array_map( function( $item ) {
return array_shift( $item );
}, $menu );
// Finally we can check if a post name is the same as any of menu item\'s label
$post_title = get_the_title( $post_id );
if ( in_array( get_the_title( $post_id ), $menu_labels ) ) {
$classes[] = sanitize_title_with_dashes( $post_title ); // you can set whatever class you want instead of $post_title. i.e. \'hidden\' or \'contact\'. In my example we are setting the same class as post title.
}
return $classes;
}
add_filter( \'post_class\', \'set_admin_post_class\', 10, 3 );