This code will add an Index value to each post which is determined by $wp_query->current_post
, the number of posts per page, and the current page being viewed.
add_filter( 'manage_posts_columns', 'wpse240648_manage_posts_columns_index');
function wpse240648_manage_posts_columns_index($columns) {
$columns['index'] = __( 'Index', 'your-text-domain' );
return $columns;
}
add_action( 'manage_posts_custom_column', 'wpse240648_manage_posts_custom_column_index', 10, 3 );
function wpse240648_manage_posts_custom_column_index( $column, $post_id ) {
if ( 'index' == $column ) {
global $wp_query;
// This line is needed to set up the query so that $wp_query->current_post works.
$wp_query->the_post();
$page_number = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 0;
if ( $page_number > 1 ) {
$current_index = ( $page_number * $wp_query->query_vars['posts_per_page'] ) - $wp_query->query_vars['posts_per_page'];
} else {
$current_index = 0;
}
echo esc_html( $wp_query->current_post + 1 + $current_index );
}
}
This code can be adapted for to work for other post types by changing the hook names appropriately:
manage_{$post_type}_posts_columns
manage_{$post_type}_posts_custom_column