1
0

functions.php 9.2 KB

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