functions.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. require(get_template_directory() . "/dist/wp_bootstrap_navwalker.php"); // bootstrap navwalker for nav
  3. /** CONFIGURATION THINGS **/
  4. add_theme_support('post-thumbnails');
  5. set_post_thumbnail_size(150, 150, true);
  6. register_nav_menu("primary", "Top Menu");
  7. /** STYLES **/
  8. function ams_enqueue_styles() {
  9. wp_enqueue_style('bootstrap', get_template_directory_uri() . '/dist/bootstrap/bootstrap.css', array(), '4.0.0-3');
  10. wp_enqueue_style('slick', get_template_directory_uri() . '/dist/slick/slick.css', array(), '1.6.0');
  11. wp_enqueue_style('slick-theme', get_template_directory_uri() . '/dist/slick/slick-theme.css', array("slick"), '1.6.0');
  12. wp_enqueue_style('ams', get_template_directory_uri() . '/style.css', array("slick", "slick-theme", "bootstrap"), '1.0.0');
  13. }
  14. function ams_enqueue_scripts() {
  15. wp_enqueue_script('bootstrap', get_template_directory_uri() . '/dist/bootstrap/bootstrap.js', array("jquery"), '4.0.0-3');
  16. wp_enqueue_script('stickyfill', get_template_directory_uri() . '/dist/stickyfill/stickyfill.js', array("jquery"), '1.1.4');
  17. wp_enqueue_script('slick', get_template_directory_uri() . '/dist/slick/slick.js', array("jquery"), '1.6.0');
  18. }
  19. add_action('wp_enqueue_scripts', 'ams_enqueue_styles');
  20. add_action('wp_enqueue_scripts', 'ams_enqueue_scripts');
  21. /** MCE BUTTON COLUMN **/
  22. function ams_quicktag() {
  23. if(wp_script_is('quicktags')) { ?>
  24. <script type="text/javascript">
  25. QTags.addButton( 'eg_ams_column', 'column', '<!--column-->', '', '', 'New column tag');
  26. </script><?php
  27. }
  28. }
  29. add_action( 'admin_print_footer_scripts', 'ams_quicktag' );
  30. /** CUSTOM POST TYPES **/
  31. add_action('init', 'create_post_types');
  32. function create_post_types() {
  33. register_post_type( 'partners',
  34. array(
  35. 'labels' => array(
  36. 'name' => __( 'Initiativpartner' ),
  37. 'singular_name' => __( 'Partner' )
  38. ),
  39. 'public' => true,
  40. 'has_archive' => true,
  41. 'menu_icon' => 'dashicons-admin-users',
  42. 'supports' => array('title', 'editor', 'thumbnail'),
  43. 'exlude_from_search' => true
  44. )
  45. );
  46. register_post_type( 'tdas',
  47. array(
  48. 'labels' => array(
  49. 'name' => __( 'TdA' ),
  50. 'singular_name' => __( 'TdA' )
  51. ),
  52. 'public' => true,
  53. 'has_archive' => true,
  54. 'menu_icon' => 'dashicons-calendar-alt',
  55. 'supports' => array('title', 'editor', 'thumbnail'),
  56. )
  57. );
  58. }
  59. /** POST META BOX **/
  60. add_action( 'load-post.php', 'ams_post_box_setup' );
  61. add_action( 'load-post-new.php', 'ams_post_box_setup' );
  62. function ams_post_box_setup() {
  63. add_action( 'add_meta_boxes', 'ams_post_box_add' );
  64. add_action( 'save_post', 'ams_post_box_save', 10, 2 );
  65. }
  66. function ams_post_box_add() {
  67. add_meta_box(
  68. 'ams_post_box', // Unique ID
  69. esc_html__( 'Post type'), // Title
  70. 'ams_post_box', // Callback function
  71. 'post', // Admin page (or post type)
  72. 'side', // Context
  73. 'default' // Priority
  74. );
  75. }
  76. function ams_post_box( $object, $box ) { ?>
  77. <?php wp_nonce_field( basename( __FILE__ ), 'ams_post_box_nonce' ); ?>
  78. <p>
  79. <label for="ams_dual_columns_post">2 Spalten</label>
  80. <input type="checkbox" name="ams_dual_columns_post" id="ams_dual_columns_post" style="float: right;" <?php if(get_post_meta($object->ID, 'ams_dual_columns_post', true)) { echo "checked"; } ?> />
  81. <br />
  82. <label for="ams_tda_gallery">TdA Gallery</label>
  83. <input type="checkbox" name="ams_tda_gallery" id="ams_tda_gallery" style="float: right;" <?php if(get_post_meta($object->ID, 'ams_tda_gallery', true)) { echo "checked"; } ?> />
  84. <br />
  85. <label for="ams_partners">Partner</label>
  86. <input type="checkbox" name="ams_partners" id="ams_partners" style="float: right;" <?php if(get_post_meta($object->ID, 'ams_partners', true)) { echo "checked"; } ?> />
  87. </p><?php
  88. }
  89. function ams_post_box_save( $post_id, $post ) {
  90. $inputs = array(
  91. "ams_dual_columns_post",
  92. "ams_tda_gallery",
  93. "ams_partners",
  94. );
  95. if(!isset( $_POST['ams_post_box_nonce']) || !wp_verify_nonce($_POST['ams_post_box_nonce'], basename(__FILE__))) {
  96. return $post_id;
  97. }
  98. $post_type = get_post_type_object( $post->post_type );
  99. if(!current_user_can( $post_type->cap->edit_post, $post_id)) {
  100. return $post_id;
  101. }
  102. foreach($inputs as $input) {
  103. if(isset($_POST[$input]) && !get_post_meta( $post_id, $input, true )) {
  104. add_post_meta( $post_id, $input, true, true );
  105. } else if(!isset($_POST[$input]) && get_post_meta( $post_id, $input, true )) {
  106. delete_post_meta( $post_id, $input);
  107. }
  108. }
  109. }
  110. /** TDAS META BOX **/
  111. /* TODO: REMOVE
  112. add_action( 'load-post.php', 'ams_tdas_box_setup' );
  113. add_action( 'load-post-new.php', 'ams_tdas_box_setup' );
  114. function ams_tdas_box_setup() {
  115. add_action( 'add_meta_boxes', 'ams_tdas_box_add' );
  116. add_action( 'save_post', 'ams_tdas_box_save', 10, 2 );
  117. }
  118. function ams_tdas_box_add() {
  119. add_meta_box(
  120. 'ams_tdas_box', // Unique ID
  121. esc_html__( 'Slider ID'), // Title
  122. 'ams_tdas_box', // Callback function
  123. 'tdas', // Admin page (or post type)
  124. 'side', // Context
  125. 'default' // Priority
  126. );
  127. }
  128. function ams_tdas_box( $object, $box ) { ?>
  129. <?php wp_nonce_field( basename( __FILE__ ), 'ams_tdas_box_nonce' ); ?>
  130. <p>
  131. <label for="ams_tda_sliderid">SliderID</label>
  132. <input type="text" name="ams_tda_sliderid" id="ams_tda_sliderid" value="<?php if(get_post_meta($object->ID, 'ams_tda_sliderid', true)) { echo get_post_meta($object->ID, 'ams_tda_sliderid', true); } ?>" />
  133. </p><?php
  134. }
  135. function ams_tdas_box_save( $post_id, $post ) {
  136. $inputs = array(
  137. "ams_tda_sliderid",
  138. );
  139. if(!isset( $_POST['ams_tdas_box_nonce']) || !wp_verify_nonce($_POST['ams_tdas_box_nonce'], basename(__FILE__))) {
  140. return $post_id;
  141. }
  142. $post_type = get_post_type_object( $post->post_type );
  143. if(!current_user_can($post_type->cap->edit_post, $post_id)) {
  144. return $post_id;
  145. }
  146. foreach($inputs as $input) {
  147. if((isset($_POST[$input]) && !empty($_POST[$input])) && !get_post_meta($post_id, $input, true)) {
  148. add_post_meta($post_id, $input, $_POST[$input]);
  149. } else if((isset($_POST[$input]) && !empty($_POST[$input])) && get_post_meta($post_id, $input, true)) {
  150. update_post_meta($post_id, $input, $_POST[$input]);
  151. } else if((!isset($_POST[$input]) || empty($_POST[$input])) && get_post_meta($post_id, $input, true)) {
  152. delete_post_meta($post_id, $input);
  153. }
  154. }
  155. }
  156. */
  157. /** TdA Slider **/
  158. global $tdaSlider; // TODO: remove this
  159. $tdaSlider = array(
  160. "TdA2016" => array(
  161. "url" => "http://www.architekturmachtschule.de/wp-content/uploads/2015/11/",
  162. "tag-der-architektur-2015-01.jpg",
  163. "tag-der-architektur-2015-02.jpg",
  164. "tag-der-architektur-2015-03.jpg",
  165. "tag-der-architektur-2015-04.jpg",
  166. "tag-der-architektur-2015-05.jpg",
  167. "tag-der-architektur-2015-06.jpg",
  168. "tag-der-architektur-2015-07.jpg",
  169. "tag-der-architektur-2015-08.jpg",
  170. "tag-der-architektur-2015-09.jpg",
  171. "tag-der-architektur-2015-10.jpg",
  172. "tag-der-architektur-2015-11.jpg",
  173. "tag-der-architektur-2015-12.jpg",
  174. "tag-der-architektur-2015-13.jpg",
  175. "tag-der-architektur-2015-14.jpg",
  176. "tag-der-architektur-2015-15.jpg",
  177. "tag-der-architektur-2015-16.jpg",
  178. "tag-der-architektur-2015-17.jpg",
  179. "tag-der-architektur-2015-18.jpg",
  180. "tag-der-architektur-2015-19.jpg",
  181. "tag-der-architektur-2015-20.jpg",
  182. "tag-der-architektur-2015-21.jpg",
  183. "tag-der-architektur-2015-22.jpg",
  184. "tag-der-architektur-2015-23.jpg",
  185. "tag-der-architektur-2015-24.jpg",
  186. "tag-der-architektur-2015-25.jpg",
  187. "tag-der-architektur-2015-26.jpg",
  188. "tag-der-architektur-2015-27.jpg",
  189. "tag-der-architektur-2015-28.jpg",
  190. "tag-der-architektur-2015-29.jpg",
  191. "tag-der-architektur-2015-30.jpg",
  192. "tag-der-architektur-2015-31.jpg",
  193. "tag-der-architektur-2015-32.jpg",
  194. "tag-der-architektur-2015-33.jpg",
  195. "tag-der-architektur-2015-34.jpg",
  196. "tag-der-architektur-2015-35.jpg",
  197. "tag-der-architektur-2015-36.jpg",
  198. "tag-der-architektur-2015-37.jpg",
  199. "tag-der-architektur-2015-38.jpg",
  200. "tag-der-architektur-2015-39.jpg",
  201. "tag-der-architektur-2015-40.jpg",
  202. "tag-der-architektur-2015-41.jpg",
  203. "tag-der-architektur-2015-42.jpg",
  204. "tag-der-architektur-2015-43.jpg"
  205. ),
  206. );
  207. // [carousel id="TdA2016"]
  208. function carousel_shortcode_func($atts) {
  209. global $tdaSlider;
  210. $a = shortcode_atts( array(
  211. 'id' => NULL
  212. ), $atts );
  213. if($a['id'] != NULL && array_key_exists($a['id'], $tdaSlider)) {
  214. $slider = $tdaSlider[$a['id']];
  215. $output = '<div class="owl-carousel">';
  216. foreach($slider as $key => $value) {
  217. if($key == "url") {
  218. continue;
  219. }
  220. $output .= '<div class="item" id="item-' . $key . '"><img id="img-' . $key . '" data-lazy="' . $slider['url'] . $value . '" style="height: 300px; width: auto;"></div>' . PHP_EOL;
  221. }
  222. $output .= '</div>';
  223. return $output;
  224. } else {
  225. return "<span style=\"color: red;\">Wrong Slider ID!</span>";
  226. }
  227. }
  228. add_shortcode('carousel', 'carousel_shortcode_func');
  229. /* TITLE STUFF */
  230. function ams_modify_titles($title, $id = null) {
  231. if(get_post_type() == "tdas") {
  232. return "Tag der Architektur" . preg_replace("/&#?[a-z0-9]{2,8};/i", "", $title) . " &raquo; " . get_bloginfo("name");
  233. }
  234. return $title . get_bloginfo("name");
  235. }
  236. add_filter( 'wp_title', 'ams_modify_titles', 10, 2 );
  237. ?>