Advertisement
Guest User

Sample for troubleshooting

a guest
Apr 10th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. // Register post type
  2. add_action( 'init', 'cw_create_ci_ads' );
  3. function cw_create_ci_ads() {
  4. register_post_type( 'ci_ads',
  5. array(
  6. 'labels' => array(
  7. 'name' => 'Ads',
  8. 'singular_name' => 'Ad',
  9. 'add_new' => 'Add New',
  10. 'add_new_item' => 'Add New Ad',
  11. 'edit' => 'Edit',
  12. 'edit_item' => 'Edit Ad',
  13. 'new_item' => 'New Ad',
  14. 'view' => 'View',
  15. 'view_item' => 'View Ad',
  16. 'search_items' => 'Search Ads',
  17. 'not_found' => 'No Ads found',
  18. 'not_found_in_trash' => 'No Ads found in Trash'
  19. ),
  20. 'hierarchical' => true,
  21. 'public' => true,
  22. 'exclude_from_search' => true,
  23. 'menu_position' => 30,
  24. 'supports' => array( 'title','thumbnail','page-attributes' ),
  25. 'taxonomies' => array( '' ),
  26. 'menu_icon' => plugins_url( 'images/icon-ci_ads.png', __FILE__ ),
  27. 'has_archive' => true,
  28. 'rewrite' => array('slug' => 'ads'),
  29. )
  30. );
  31. }
  32.  
  33. // Add columns to the overview page for a cpt
  34. function cw_add_custom_columns( $cols ) {
  35. $cols = array(
  36. 'cb' => '<input type="checkbox" />',// leave this here or mass edit/delete will not work
  37. 'title' => __( 'Title' ),
  38. 'ci_ad_size' => __( 'Size' ),
  39. 'ci_ad_url' => __( 'URL' ), );
  40. return $cols;
  41. }
  42. add_filter( "manage_ci_ads_posts_columns", "cw_add_custom_columns" );
  43.  
  44. // Populate the columns
  45. function cw_populate_custom_columns( $column, $post_id ) {
  46. switch ( $column ) {
  47. case "ci_ad_size":
  48. $ad_size = get_post_meta( $post_id, 'ci_ad_size', true);
  49. echo '<a style="text-transform:capitalize;" href="' . $ad_size . '">' . $ad_size. '</a>';
  50. break;
  51. case "ci_ad_url":
  52. $ad_url = get_post_meta( $post_id, 'ci_ad_url', true);
  53. echo '<a href="' . $ad_url . '">' . $ad_url. '</a>';
  54. break;
  55. case "ci_ad_image":
  56. $ad_image = get_post_meta( $post_id, the_post_thumbnail(), true);
  57. echo '<a href="' . $ad_image . '">' . $ad_image. '</a>';
  58. break;
  59. }
  60. }
  61. add_action( "manage_posts_custom_column", "cw_populate_custom_columns", 10, 2 ); // what are the 10 and 2?
  62.  
  63. // Make the new columns sortable
  64. function cw_sortable_custom_columns() {
  65. return array(
  66. 'ci_ad_url' => 'ci_ad_url',
  67. 'ci_ad_size' => 'ci_ad_size'
  68. );
  69. }
  70. add_filter( "manage_edit-ci_ads_sortable_columns", "cw_sortable_custom_columns" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement