films-cpt.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. function ph_films() {
  3. $labels = array(
  4. 'name' => _x('Films', 'post type general name'),
  5. 'singular_name' => _x('Film', 'post type singular name'),
  6. 'add_new' => _x('Add New Film', 'Film item'),
  7. 'add_new_item' => __('Add New Film'),
  8. 'edit_item' => __('Edit Film'),
  9. 'new_item' => __('New Film'),
  10. 'view_item' => __('View Film'),
  11. 'search_items' => __('Search Films'),
  12. 'not_found' => __('No Films found'),
  13. 'not_found_in_trash' => __('No Films found in Trash'),
  14. 'parent_item_colon' => ''
  15. );
  16. $args = array(
  17. 'labels' => $labels,
  18. 'public' => true,
  19. 'publicly_queryable' => true,
  20. 'show_ui' => true,
  21. 'query_var' => true,
  22. 'capability_type' => 'post',
  23. 'hierarchical' => false,
  24. 'rewrite' => array("slug" => "films"),
  25. 'menu_position' => 3,
  26. 'supports' => array('title','editor','thumbnail','excerpt'),
  27. 'menu_icon' => get_stylesheet_directory_uri() . '/img/film-icon.jpg',
  28. );
  29. if (class_exists('MultiPostThumbnails')) {
  30. new MultiPostThumbnails(array(
  31. 'label' => 'Cover',
  32. 'id' => 'secondary-image',
  33. 'post_type' => 'film'
  34. )
  35. );
  36. new MultiPostThumbnails(array(
  37. 'label' => 'Films Page Image',
  38. 'id' => 'secondary-image-2',
  39. 'post_type' => 'film'
  40. )
  41. );
  42. }
  43. register_post_type( 'Film' , $args );
  44. }
  45. add_action('init', 'ph_films');
  46. register_taxonomy("type", array("film"), array("hierarchical" => true, "label" => "Types", "singular_label" => "Type", "rewrite" => true));
  47. add_action("admin_init", "phf_meta_init");
  48. function phf_meta_init(){
  49. add_meta_box("phf_year", "Year", "phf_year", "Film", "side", "high");
  50. add_meta_box("phf_video", "Videos", "phf_video", "Film", "side", "low");
  51. add_meta_box("phf_credits", "Credits", "phf_credits", "Film", "advanced", "low");
  52. add_meta_box("phf_publicity", "Publicity", "phf_publicity", "Film", "advanced", "low");
  53. add_meta_box("phf_reviews", "Reviews", "phf_reviews", "Film", "advanced", "low");
  54. add_meta_box("phf_featuring", "Featuring", "phf_featuring", "Film", "advanced", "low");
  55. add_meta_box("phf_color", "Colors", "phf_color", "Film", "side", "low");
  56. add_meta_box("phf_price", "Purchase Options", "phf_price", "Film", "side", "low");
  57. //echo '<input type="hidden" name="ph_nonce" value="' . wp_create_nonce(__FILE__) . '" />';
  58. }
  59. function phf_year(){
  60. global $post;
  61. $custom = get_post_custom($post->ID);
  62. $ph_year = $custom["ph_year"][0];
  63. ?>
  64. <label>Year</label>
  65. <input name="ph_year" value="<?php echo $ph_year; ?>" />
  66. <?php
  67. }
  68. function phf_video() {
  69. global $post;
  70. $custom = get_post_custom($post->ID);
  71. $video = $custom["video"][0];
  72. ?>
  73. <label>URL:</label>
  74. <input name="video" value="<?php echo $video; ?>" />
  75. <?php
  76. }
  77. function phf_credits() {
  78. global $post;
  79. $custom = get_post_custom($post->ID);
  80. $credits = $custom["credits"][0];
  81. ?>
  82. <div class="customEditor"><label>Credits:</label><br />
  83. <textarea cols="70" rows="5" name="credits"><?php echo $credits; ?></textarea></div>
  84. <?php
  85. }
  86. function phf_publicity() {
  87. global $post;
  88. $custom = get_post_custom($post->ID);
  89. $publicity = $custom["publicity"][0];
  90. ?>
  91. <div class="customEditor"><label>Publicity:</label><br />
  92. <textarea cols="70" rows="5" name="publicity"><?php echo $publicity; ?></textarea></div>
  93. <?php
  94. }
  95. function phf_reviews() {
  96. global $post;
  97. $custom = get_post_custom($post->ID);
  98. $reviews = $custom["reviews"][0];
  99. ?>
  100. <p><label>Reviews:</label><br />
  101. <textarea cols="70" rows="5" name="reviews"><?php echo $reviews; ?></textarea></p>
  102. <?php
  103. }
  104. function phf_featuring() {
  105. global $post;
  106. $custom = get_post_custom($post->ID);
  107. $featuring = $custom["featuring"][0];
  108. ?>
  109. <p><label>Featuring:</label><br />
  110. <textarea cols="70" rows="5" name="featuring"><?php echo $featuring; ?></textarea></p>
  111. <?php
  112. }
  113. function phf_color() {
  114. global $post;
  115. $custom = get_post_custom($post->ID);
  116. $custom2 = get_post_custom($post->ID);
  117. $custom3 = get_post_custom($post->ID);
  118. $color = $custom["color"][0];
  119. $color2 = $custom2["color2"][0];
  120. $color3 = $custom3["color3"][0];
  121. ?>
  122. <label>HEX:</label><input name="color" value="<?php echo $color; ?>" /><br />
  123. <label>HEX:</label><input name="color2" value="<?php echo $color2; ?>" /><br />
  124. <label>HEX:</label><input name="color3" value="<?php echo $color3; ?>" />
  125. <?php
  126. }
  127. function phf_price() {
  128. global $post;
  129. $custom = get_post_custom($post->ID);
  130. $custom2 = get_post_custom($post->ID);
  131. $custom3 = get_post_custom($post->ID);
  132. $custom4 = get_post_custom($post->ID);
  133. $price = $custom["price"][0];
  134. $price2 = $custom2["price2"][0];
  135. $price3 = $custom3["price3"][0];
  136. $price4 = $custom4["price4"][0];
  137. ?>
  138. <p>Price: (no dollar sign)</p>
  139. <label>Personal:</label><input name="price" value="<?php echo $price; ?>" /><br />
  140. <label>Library:</label><input name="price2" value="<?php echo $price2; ?>" /><br />
  141. <label>University:</label><input name="price3" value="<?php echo $price3; ?>" /><br />
  142. <p>Vendor/Distributor</p>
  143. <label>URL:</label><input name="price4" value="<?php echo $price4; ?>" /><br />
  144. <?php
  145. }
  146. add_action('save_post', 'phf_meta_save');
  147. function phf_meta_save(){
  148. global $post;
  149. //if (!wp_verify_nonce($_POST['ph_nonce'],__FILE__)) return $post_id;
  150. if ( !current_user_can( 'edit_post', $post->ID ))
  151. return $post->ID;
  152. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
  153. return $post->ID;
  154. }
  155. if( $post->post_type == 'film' ) {
  156. if (isset( $_POST ) ) {
  157. update_post_meta($post->ID, "ph_year", $_POST["ph_year"]);
  158. update_post_meta($post->ID, "video", $_POST["video"]);
  159. update_post_meta($post->ID, "credits", $_POST["credits"]);
  160. update_post_meta($post->ID, "publicity", $_POST["publicity"]);
  161. update_post_meta($post->ID, "featuring", $_POST["featuring"]);
  162. update_post_meta($post->ID, "reviews", $_POST["reviews"]);
  163. update_post_meta($post->ID, "color", $_POST["color"]);
  164. update_post_meta($post->ID, "color2", $_POST["color2"]);
  165. update_post_meta($post->ID, "color3", $_POST["color3"]);
  166. update_post_meta($post->ID, "price", $_POST["price"]);
  167. update_post_meta($post->ID, "price2", $_POST["price2"]);
  168. update_post_meta($post->ID, "price3", $_POST["price3"]);
  169. update_post_meta($post->ID, "price4", $_POST["price4"]);
  170. }
  171. }
  172. }
  173. add_action('manage_film_posts_custom_column', 'manage_film_columns', 10, 2);
  174. function manage_film_columns($column_name, $id) {
  175. global $wpdb;
  176. switch ($column_name) {
  177. case 'id':
  178. echo $id;
  179. break;
  180. case "thumbnail":
  181. echo the_post_thumbnail('small');
  182. break;
  183. case "cover":
  184. echo MultiPostThumbnails::the_post_thumbnail_thumb('film', 'secondary-image');
  185. break;
  186. case 'images':
  187. $num_images = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = %d", $id ));
  188. echo $num_images;
  189. break;
  190. default:
  191. break;
  192. }
  193. }
  194. add_filter('manage_edit-film_columns', 'add_new_film_columns');
  195. function add_new_film_columns($film_columns) {
  196. $new_columns['cb'] = '<input type="checkbox" />';
  197. $new_columns['title'] = __('Film Name', 'column name');
  198. $new_columns['images'] = __('Images');
  199. $new_columns['thumbnail'] = __('thumbnail');
  200. $new_columns['cover'] = __('cover');
  201. $new_columns['date'] = __('Date', 'column name');
  202. return $new_columns;
  203. }
  204. add_action( 'admin_head', 'phf_icons' );
  205. function phf_icons() { ?>
  206. <style type="text/css" media="screen">
  207. #icon-edit.icon32-posts-film {background: url(<?php bloginfo('template_url') ?>/img/film-icon.png) no-repeat;}
  208. </style>
  209. <?php }
  210. add_action('admin_print_footer_scripts','my_admin_print_footer_scripts',99);
  211. function my_admin_print_footer_scripts()
  212. {
  213. ?><script type="text/javascript">/* <![CDATA[ */
  214. jQuery(function($)
  215. {
  216. var i=1;
  217. $('.customEditor textarea').each(function(e)
  218. {
  219. var id = $(this).attr('id');
  220. if (!id)
  221. {
  222. id = 'customEditor-' + i++;
  223. $(this).attr('id',id);
  224. }
  225. tinyMCE.execCommand('mceAddControl', false, id);
  226. });
  227. });
  228. /* ]]> */</script><?php
  229. }
  230. add_action("template_redirect", 'ph_redirect');
  231. function ph_redirect(){
  232. global $wp;
  233. global $wp_query;
  234. global $post;
  235. if (isset($wp->query_vars["post_type"]) && $wp->query_vars["post_type"] != 'post' && $wp->query_vars["post_type"] != 'page') :
  236. if ( file_exists(TEMPLATEPATH . '/' . $wp->query_vars["post_type"] . '.php') ) :
  237. $ph_template = TEMPLATEPATH . '/' . $wp->query_vars["post_type"] . '.php';
  238. elseif ( file_exists(TEMPLATEPATH . '/t_' . $wp->query_vars["post_type"] . '.php') ) :
  239. $ph_template = TEMPLATEPATH . '/t_' . $wp->query_vars["post_type"] . '.php';
  240. endif;
  241. if(isset($ph_template)) :
  242. if (have_posts()) :
  243. include($ph_template);
  244. die();
  245. else :
  246. $wp_query->is_404 = true;
  247. endif;
  248. endif;
  249. endif;
  250. }
  251. ?>