films-cpt.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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' => 'dashicons-format-video',
  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; ?>" style="width: 500px;"/>
  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( !is_object($post) ) {return;}
  150. if( $post->post_type == 'film' ) {
  151. if (isset( $_POST ) ) {
  152. update_post_meta($post->ID, "ph_year", $_POST["ph_year"]);
  153. update_post_meta($post->ID, "video", $_POST["video"]);
  154. update_post_meta($post->ID, "credits", $_POST["credits"]);
  155. update_post_meta($post->ID, "publicity", $_POST["publicity"]);
  156. update_post_meta($post->ID, "featuring", $_POST["featuring"]);
  157. update_post_meta($post->ID, "reviews", $_POST["reviews"]);
  158. update_post_meta($post->ID, "color", $_POST["color"]);
  159. update_post_meta($post->ID, "color2", $_POST["color2"]);
  160. update_post_meta($post->ID, "color3", $_POST["color3"]);
  161. update_post_meta($post->ID, "price", $_POST["price"]);
  162. update_post_meta($post->ID, "price2", $_POST["price2"]);
  163. update_post_meta($post->ID, "price3", $_POST["price3"]);
  164. update_post_meta($post->ID, "price4", $_POST["price4"]);
  165. }
  166. }
  167. }
  168. add_action('manage_film_posts_custom_column', 'manage_film_columns', 10, 2);
  169. function manage_film_columns($column_name, $id) {
  170. global $wpdb;
  171. switch ($column_name) {
  172. case 'id':
  173. echo $id;
  174. break;
  175. case "thumbnail":
  176. echo the_post_thumbnail('small');
  177. break;
  178. case "cover":
  179. echo MultiPostThumbnails::the_post_thumbnail_thumb('film', 'secondary-image');
  180. break;
  181. case 'images':
  182. $num_images = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = %d", $id ));
  183. echo $num_images;
  184. break;
  185. default:
  186. break;
  187. }
  188. }
  189. add_filter('manage_edit-film_columns', 'add_new_film_columns');
  190. function add_new_film_columns($film_columns) {
  191. $new_columns['cb'] = '<input type="checkbox" />';
  192. $new_columns['title'] = __('Film Name', 'column name');
  193. $new_columns['images'] = __('Images');
  194. $new_columns['thumbnail'] = __('thumbnail');
  195. $new_columns['cover'] = __('cover');
  196. $new_columns['date'] = __('Date', 'column name');
  197. return $new_columns;
  198. }
  199. add_action( 'admin_head', 'phf_icons' );
  200. function phf_icons() { ?>
  201. <style type="text/css" media="screen">
  202. #icon-edit.icon32-posts-film {background: url(<?php bloginfo('template_url') ?>/img/film-icon.png) no-repeat;}
  203. </style>
  204. <?php }
  205. add_action('admin_print_footer_scripts','my_admin_print_footer_scripts',99);
  206. function my_admin_print_footer_scripts()
  207. {
  208. ?><script type="text/javascript">/* <![CDATA[ */
  209. jQuery(function($)
  210. {
  211. var i=1;
  212. $('.customEditor textarea').each(function(e)
  213. {
  214. var id = $(this).attr('id');
  215. if (!id)
  216. {
  217. id = 'customEditor-' + i++;
  218. $(this).attr('id',id);
  219. }
  220. tinyMCE.execCommand('mceAddControl', false, id);
  221. });
  222. });
  223. /* ]]> */</script><?php
  224. }
  225. add_action("template_redirect", 'ph_redirect');
  226. function ph_redirect(){
  227. global $wp;
  228. global $wp_query;
  229. global $post;
  230. if (isset($wp->query_vars["post_type"]) && $wp->query_vars["post_type"] != 'post' && $wp->query_vars["post_type"] != 'page') :
  231. if ( file_exists(TEMPLATEPATH . '/' . $wp->query_vars["post_type"] . '.php') ) :
  232. $ph_template = TEMPLATEPATH . '/' . $wp->query_vars["post_type"] . '.php';
  233. elseif ( file_exists(TEMPLATEPATH . '/t_' . $wp->query_vars["post_type"] . '.php') ) :
  234. $ph_template = TEMPLATEPATH . '/t_' . $wp->query_vars["post_type"] . '.php';
  235. endif;
  236. if(isset($ph_template)) :
  237. if (have_posts()) :
  238. include($ph_template);
  239. die();
  240. else :
  241. $wp_query->is_404 = true;
  242. endif;
  243. endif;
  244. endif;
  245. }
  246. ?>