Custom Post Type: Senior Leaders


/ Published in: PHP
Save to your folder(s)

Place into fucntions.php


Copy this code and paste it in your HTML
  1. /******* CUSTOM POST TYPE: SENIOR LEADERS *********/
  2.  
  3. add_action('init', 'sl_register');
  4.  
  5. function sl_register() {
  6. $args = array(
  7. 'label' => __('Senior Leaders'),
  8. 'singular_label' => __('Senior Leader'),
  9. 'public' => true,
  10. 'show_ui' => true,
  11. 'capability_type' => 'post',
  12. 'hierarchical' => false,
  13. 'rewrite' => true,
  14. 'supports' => array('title', 'thumbnail')
  15. );
  16.  
  17. register_post_type( 'senior-leader' , $args );
  18. }
  19.  
  20. add_action("admin_init", "sl_admin_init");
  21. add_action('save_post', 'save_sl_meta');
  22.  
  23. function sl_admin_init(){
  24. add_meta_box("sl_meta", "Senior Leader Options", "sl_meta_options", "senior-leader", "normal", "core");
  25. }
  26.  
  27. function sl_meta_options(){
  28. global $post;
  29. $custom = get_post_custom($post->ID);
  30. $sl_suffix = $custom["sl_suffix"][0];
  31. $sl_jobtitle = $custom["sl_jobtitle"][0];
  32.  
  33. ?>
  34. <div style="float:left;padding:5px 15px;">
  35. <label for="sl_suffix">Suffix </label>
  36. <input type="text" name="sl_suffix" size="20" autocomplete="on" value="<?php echo $sl_suffix; ?>">
  37. </div>
  38. <div style="float:left;padding:5px 15px;">
  39. <label for="sl_jobtitle">Job Title </label>
  40. <input type="text" name="sl_jobtitle" size="30" autocomplete="on" value="<?php echo $sl_jobtitle; ?>">
  41. </div>
  42. <p>&nbsp;</p>
  43. <p>&nbsp;</p>
  44. <?php
  45. }
  46.  
  47. function save_sl_meta(){
  48. global $post;
  49. update_post_meta($post->ID, "sl_suffix", $_POST["sl_suffix"]);
  50. update_post_meta($post->ID, "sl_jobtitle", $_POST["sl_jobtitle"]);
  51. }
  52.  
  53. add_filter("manage_edit-senior-leader_columns", "sl_edit_columns");
  54. add_action("manage_posts_custom_column", "sl_custom_columns");
  55.  
  56. function sl_edit_columns($columns){
  57. $columns = array(
  58. "cb" => "<input type=\"checkbox\" />",
  59. "title" => "Name",
  60. "sl_suffix" => "Suffix",
  61. "sl_jobtitle" => "Job Title",
  62. "sl_image" => "Featured Image"
  63. );
  64.  
  65. return $columns;
  66. }
  67.  
  68. function sl_custom_columns($column){
  69. global $post;
  70. switch ($column)
  71. {
  72. case "sl_suffix":
  73. $custom = get_post_custom();
  74. echo $custom["sl_suffix"][0];
  75. break;
  76. case "sl_jobtitle":
  77. $custom = get_post_custom();
  78. echo $custom["sl_jobtitle"][0];
  79. break;
  80. case "sl_image":
  81. $sl_thumb = get_thumbnail($post->ID,"60","75");
  82. echo "<img src=\"". $sl_thumb ."\" />";
  83. break;
  84. }
  85. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.