Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <?php
  2. // Add custom column in custom post type (here custom_post = latest_at_sonic)
  3.  
  4. add_filter( 'manage_edit-latest_at_sonic_columns', 'my_edit_latest_at_sonic_columns' ) ;
  5.  
  6. function my_edit_latest_at_sonic_columns( $columns ) {
  7.  
  8. $columns = array(
  9. 'cb' => '<input type="checkbox" />',
  10. 'title' => __( 'Title' ),
  11. 'description' => __( 'Description' ),
  12. 'thumbnail' => __( 'Thumbnail' ),
  13. 'date' => __( 'Date' )
  14. );
  15.  
  16. return $columns;
  17. }
  18.  
  19. add_action( 'manage_latest_at_sonic_posts_custom_column', 'my_manage_latest_at_sonic_columns', 10, 2 );
  20.  
  21. function my_manage_latest_at_sonic_columns( $column, $post_id ) {
  22. global $post;
  23.  
  24. switch( $column ) {
  25.  
  26. /* If displaying the 'description' column. */
  27. case 'description' :
  28.  
  29. /* Get the post meta. */
  30. $description = get_the_content( $post_id );
  31. $short_desc = substr($description, 0, 80);
  32.  
  33. /* If no short_desc is found, output a default message. */
  34. if ( empty( $short_desc ) )
  35. echo __( '-' );
  36.  
  37. /* If there is a short_desc, append 'minutes' to the text string. */
  38. else
  39. printf( __( '%s' ), $short_desc );
  40.  
  41.  
  42. break;
  43.  
  44. /* If displaying the 'thumbnail' column. */
  45. case 'thumbnail' :
  46.  
  47. /* Get the genres for the post. */
  48. $thumbnail = get_the_post_thumbnail( $post_id, array( 100, 100) );
  49.  
  50. /* If terms were found. */
  51. if ( !empty( $thumbnail ) ) {
  52.  
  53.  
  54. /* Join the terms, separating them with a comma. */
  55. echo $thumbnail;
  56. }
  57.  
  58. /* If no terms were found, output a default message. */
  59. else {
  60. _e( '-' );
  61. }
  62.  
  63. break;
  64.  
  65. /* Just break out of the switch statement for everything else. */
  66. default :
  67. break;
  68. }
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement