Advertisement
Barbareshet

show posts views column in main articles page

May 8th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. /*
  2.  * show posts views column in main articles page
  3.  *
  4.  */
  5. function add_articles_views_column($columns) {
  6.     return array_merge( $columns,
  7.         array('views' => __('Views')) );
  8. }
  9. add_filter('manage_articles_posts_columns' , 'add_articles_views_column');
  10.  
  11.  
  12. function my_articles_views_columns( $column, $post_id ){
  13.     global $post;
  14.     switch ($column){
  15.         case 'views':
  16.             $views = get_post_meta($post_id, 'post_views_count', true );
  17.             /* If no duration is found, output a default message. */
  18.             if ( empty( $views ) )
  19.             echo __( 'No Views' );
  20.  
  21.             /* If there is a duration, append 'minutes' to the text string. */
  22.         else
  23.             printf( __( '%s views' ), $views );
  24.             break;
  25.     }
  26. }
  27. add_action( 'manage_articles_posts_custom_column', 'my_articles_views_columns', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement