这并不容易,因为没有钩子来添加行操作。但是,您可以取消注册日期列,并使用添加的行操作重新注册自己的日期列。不幸的是,有点黑。
我已尝试确保以下代码适用于帖子类型“推荐”
首先注册新的日期列,然后注销旧的:(使用manage_{post_type}_posts_columns
挂钩)
add_filter(\'manage_testimonials_posts_columns\', \'my_custom_date_column_head\');
function my_custom_date_column_head($columns) {
$columns[\'date2\'] = \'Date\';
unset( $columns[\'date\'] );
return $columns;
}
然后使新的日期列可排序(按“日期”)。使用
manage_edit-{post_type}_sortable_columns
挂钩)
add_filter( \'manage_edit-testimonials_sortable_columns\', \'my_custom_date_column_sort\' );
function my_custom_date_column_sort( $columns ) {
$columns[\'date2\'] = \'date\';
return $columns;
}
现在是有趣的一点-显示专栏的内容。我几乎复制并粘贴了WordPress用来填充日期列的内容,然后在末尾添加了操作。
使用manage_{post_type}_posts_custom_columns
挂钩)
add_action( "manage_testimonials_posts_custom_column", \'my_custom_date_column_content\',10,2);
function my_custom_date_column_content($column, $post_id ){
global $post,$mode;
if( \'date2\' != $column )
return;
//**** Display default content of date column *******//
if ( \'0000-00-00 00:00:00\' == $post->post_date ) {
$t_time = $h_time = __( \'Unpublished\' );
$time_diff = 0;
} else {
$t_time = get_the_time( __( \'Y/m/d g:i:s A\' ) );
$m_time = $post->post_date;
$time = get_post_time( \'G\', true, $post );
$time_diff = time() - $time;
if ( $time_diff > 0 && $time_diff < 24*60*60 )
$h_time = sprintf( __( \'%s ago\' ), human_time_diff( $time ) );
else
$h_time = mysql2date( __( \'Y/m/d\' ), $m_time );
}
if ( \'excerpt\' == $mode )
echo apply_filters( \'post_date_column_time\', $t_time, $post, $column, $mode );
else
echo \'<abbr title="\' . $t_time . \'">\' . apply_filters( \'post_date_column_time\', $h_time, $post, $column, $mode ) . \'</abbr>\';
echo \'<br />\';
if ( \'publish\' == $post->post_status ) {
_e( \'Published\' );
} elseif ( \'future\' == $post->post_status ) {
if ( $time_diff > 0 )
echo \'<strong class="attention">\' . __( \'Missed schedule\' ) . \'</strong>\';
else
_e( \'Scheduled\' );
} else {
_e( \'Last Modified\' );
}
//***** END -- Display default content of date column *******//
//***** START -- Our actions *******//
//First set up some variables
$actions = array();
$post_type_object = get_post_type_object( $post->post_type );
$can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
//Actions to edit
if ( $can_edit_post && \'trash\' != $post->post_status ) {
$actions[\'edit\'] = \'<a href="\' . get_edit_post_link( $post->ID, true ) . \'" title="\' . esc_attr( __( \'Edit this item\' ) ) . \'">\' . __( \'Edit\' ) . \'</a>\';
$actions[\'inline hide-if-no-js\'] = \'<a href="#" class="editinline" title="\' . esc_attr( __( \'Edit this item inline\' ) ) . \'">\' . __( \'Quick Edit\' ) . \'</a>\';
}
//Actions to delete/trash
if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
if ( \'trash\' == $post->post_status )
$actions[\'untrash\'] = "<a title=\'" . esc_attr( __( \'Restore this item from the Trash\' ) ) . "\' href=\'" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . \'&action=untrash\', $post->ID ) ), \'untrash-\' . $post->post_type . \'_\' . $post->ID ) . "\'>" . __( \'Restore\' ) . "</a>";
elseif ( EMPTY_TRASH_DAYS )
$actions[\'trash\'] = "<a class=\'submitdelete\' title=\'" . esc_attr( __( \'Move this item to the Trash\' ) ) . "\' href=\'" . get_delete_post_link( $post->ID ) . "\'>" . __( \'Trash\' ) . "</a>";
if ( \'trash\' == $post->post_status || !EMPTY_TRASH_DAYS )
$actions[\'delete\'] = "<a class=\'submitdelete\' title=\'" . esc_attr( __( \'Delete this item permanently\' ) ) . "\' href=\'" . get_delete_post_link( $post->ID, \'\', true ) . "\'>" . __( \'Delete Permanently\' ) . "</a>";
}
//Actions to view/preview
if ( in_array( $post->post_status, array( \'pending\', \'draft\', \'future\' ) ) ) {
if ( $can_edit_post )
$actions[\'view\'] = \'<a href="\' . esc_url( add_query_arg( \'preview\', \'true\', get_permalink( $post->ID ) ) ) . \'" title="\' . esc_attr( sprintf( __( \'Preview “%s”\' ), $title ) ) . \'" rel="permalink">\' . __( \'Preview\' ) . \'</a>\';
} elseif ( \'trash\' != $post->post_status ) {
$actions[\'view\'] = \'<a href="\' . get_permalink( $post->ID ) . \'" title="\' . esc_attr( sprintf( __( \'View “%s”\' ), $title ) ) . \'" rel="permalink">\' . __( \'View\' ) . \'</a>\';
}
//***** END -- Our actions *******//
//Echo the \'actions\' HTML, let WP_List_Table do the hard work
echo WP_List_Table::row_actions( $actions );
}