Advertisement
terorama

WP / Custom post type

Mar 10th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.79 KB | None | 0 0
  1. add_action('init', 'portfolio_register');
  2.  
  3. function portfolio_register() {
  4.  
  5.     $labels = array(
  6.         'name' => _x('My Portfolio', 'post type general name'),
  7.         'singular_name' => _x('Portfolio Item', 'post type singular name'),
  8.         'add_new' => _x('Add New', 'portfolio item'),
  9.         'add_new_item' => __('Add New Portfolio Item'),
  10.         'edit_item' => __('Edit Portfolio Item'),
  11.         'new_item' => __('New Portfolio Item'),
  12.         'view_item' => __('View Portfolio Item'),
  13.         'search_items' => __('Search Portfolio'),
  14.         'not_found' =>  __('Nothing found'),
  15.         'not_found_in_trash' => __('Nothing found in Trash'),
  16.         'parent_item_colon' => ''
  17.     );
  18.  
  19.     $args = array(
  20.         'labels' => $labels,
  21.         'public' => true,
  22.         'publicly_queryable' => true,
  23.         'show_ui' => true,
  24.         'query_var' => true,
  25.         'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
  26.         'rewrite' => true,
  27.         'capability_type' => 'post',
  28.         'hierarchical' => false,
  29.         'menu_position' => null,
  30.         'supports' => array('title','editor','thumbnail')
  31.       );
  32.  
  33.     register_post_type( 'portfolio' , $args );
  34. }
  35.  
  36. register_taxonomy("Skills", array("portfolio"), array("hierarchical" => true, "label" => "Skills", "singular_label" => "Skill", "rewrite" => true));
  37.  
  38. add_action("admin_init", "admin_init");
  39.  
  40. function admin_init(){
  41.   add_meta_box("year_completed-meta", "Year Completed", "year_completed", "portfolio", "side", "low");
  42.   add_meta_box("credits_meta", "Design & Build Credits", "credits_meta", "portfolio", "normal", "low");
  43. }
  44.  
  45. function year_completed(){
  46.   global $post;
  47.   $custom = get_post_custom($post->ID);
  48.   $year_completed = $custom["year_completed"][0];
  49.   ?>
  50.   <label>Year:</label>
  51.   <input name="year_completed" value="<?php echo $year_completed; ?>" />
  52.   <?php
  53. }
  54.  
  55. function credits_meta() {
  56.   global $post;
  57.   $custom = get_post_custom($post->ID);
  58.   $designers = $custom["designers"][0];
  59.   $developers = $custom["developers"][0];
  60.   $producers = $custom["producers"][0];
  61.   ?>
  62.   <p><label>Designed By:</label><br />
  63.   <textarea cols="50" rows="5" name="designers"><?php echo $designers; ?></textarea></p>
  64.   <p><label>Built By:</label><br />
  65.   <textarea cols="50" rows="5" name="developers"><?php echo $developers; ?></textarea></p>
  66.   <p><label>Produced By:</label><br />
  67.   <textarea cols="50" rows="5" name="producers"><?php echo $producers; ?></textarea></p>
  68.   <?php
  69. }
  70.  
  71. add_action('save_post', 'save_details');
  72.  
  73. function save_details(){
  74.   global $post;
  75.  
  76.   update_post_meta($post->ID, "year_completed", $_POST["year_completed"]);
  77.   update_post_meta($post->ID, "designers", $_POST["designers"]);
  78.   update_post_meta($post->ID, "developers", $_POST["developers"]);
  79.   update_post_meta($post->ID, "producers", $_POST["producers"]);
  80. }
  81.  
  82. add_action("manage_posts_custom_column",  "portfolio_custom_columns");
  83. add_filter("manage_edit-portfolio_columns", "portfolio_edit_columns");
  84.  
  85. function portfolio_edit_columns($columns){
  86.   $columns = array(
  87.     "cb" => "<input type="checkbox" />",
  88.     "title" => "Portfolio Title",
  89.     "description" => "Description",
  90.     "year" => "Year Completed",
  91.     "skills" => "Skills",
  92.   );
  93.  
  94.   return $columns;
  95. }
  96. function portfolio_custom_columns($column){
  97.   global $post;
  98.  
  99.   switch ($column) {
  100.     case "description":
  101.       the_excerpt();
  102.       break;
  103.     case "year":
  104.       $custom = get_post_custom();
  105.       echo $custom["year_completed"][0];
  106.       break;
  107.     case "skills":
  108.       echo get_the_term_list($post->ID, 'Skills', '', ', ','');
  109.       break;
  110.   }
  111. }
  112.  
  113. add_theme_support('post-thumbnails');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement