functions.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <?php
  2. /*
  3. Author: Eddie Machado
  4. URL: http://themble.com/bones/
  5. This is where you can drop your custom functions or
  6. just edit things like thumbnail sizes, header images,
  7. sidebars, comments, etc.
  8. */
  9. // LOAD BONES CORE (if you remove this, the theme will break)
  10. require_once( 'library/bones.php' );
  11. // CUSTOMIZE THE WORDPRESS ADMIN (off by default)
  12. // require_once( 'library/admin.php' );
  13. /*********************
  14. LAUNCH BONES
  15. Let's get everything up and running.
  16. *********************/
  17. function bones_ahoy() {
  18. //Allow editor style.
  19. add_editor_style( get_stylesheet_directory_uri() . '/library/css/editor-style.css' );
  20. // let's get language support going, if you need it
  21. load_theme_textdomain( 'bonestheme', get_template_directory() . '/library/translation' );
  22. // USE THIS TEMPLATE TO CREATE CUSTOM POST TYPES EASILY
  23. require_once( 'library/custom-post-type.php' );
  24. // launching operation cleanup
  25. add_action( 'init', 'bones_head_cleanup' );
  26. // A better title
  27. add_filter( 'wp_title', 'rw_title', 10, 3 );
  28. // remove WP version from RSS
  29. add_filter( 'the_generator', 'bones_rss_version' );
  30. // remove pesky injected css for recent comments widget
  31. add_filter( 'wp_head', 'bones_remove_wp_widget_recent_comments_style', 1 );
  32. // clean up comment styles in the head
  33. add_action( 'wp_head', 'bones_remove_recent_comments_style', 1 );
  34. // clean up gallery output in wp
  35. add_filter( 'gallery_style', 'bones_gallery_style' );
  36. // enqueue base scripts and styles
  37. add_action( 'wp_enqueue_scripts', 'bones_scripts_and_styles', 999 );
  38. // ie conditional wrapper
  39. // launching this stuff after theme setup
  40. bones_theme_support();
  41. // adding sidebars to Wordpress (these are created in functions.php)
  42. add_action( 'widgets_init', 'bones_register_sidebars' );
  43. // cleaning up random code around images
  44. add_filter( 'the_content', 'bones_filter_ptags_on_images' );
  45. // cleaning up excerpt
  46. add_filter( 'excerpt_more', 'bones_excerpt_more' );
  47. } /* end bones ahoy */
  48. // let's get this party started
  49. add_action( 'after_setup_theme', 'bones_ahoy' );
  50. /************* OEMBED SIZE OPTIONS *************/
  51. if ( ! isset( $content_width ) ) {
  52. $content_width = 680;
  53. }
  54. /************* THUMBNAIL SIZE OPTIONS *************/
  55. // Thumbnail sizes
  56. add_image_size( 'bones-thumb-600', 600, 150, true );
  57. add_image_size( 'bones-thumb-300', 300, 100, true );
  58. /*
  59. to add more sizes, simply copy a line from above
  60. and change the dimensions & name. As long as you
  61. upload a "featured image" as large as the biggest
  62. set width or height, all the other sizes will be
  63. auto-cropped.
  64. To call a different size, simply change the text
  65. inside the thumbnail function.
  66. For example, to call the 300 x 100 sized image,
  67. we would use the function:
  68. <?php the_post_thumbnail( 'bones-thumb-300' ); ?>
  69. for the 600 x 150 image:
  70. <?php the_post_thumbnail( 'bones-thumb-600' ); ?>
  71. You can change the names and dimensions to whatever
  72. you like. Enjoy!
  73. */
  74. add_filter( 'image_size_names_choose', 'bones_custom_image_sizes' );
  75. function bones_custom_image_sizes( $sizes ) {
  76. return array_merge( $sizes, array(
  77. 'bones-thumb-600' => __('600px by 150px'),
  78. 'bones-thumb-300' => __('300px by 100px'),
  79. ) );
  80. }
  81. /*
  82. The function above adds the ability to use the dropdown menu to select
  83. the new images sizes you have just created from within the media manager
  84. when you add media to your content blocks. If you add more image sizes,
  85. duplicate one of the lines in the array and name it according to your
  86. new image size.
  87. */
  88. /************* THEME CUSTOMIZE *********************/
  89. /*
  90. A good tutorial for creating your own Sections, Controls and Settings:
  91. http://code.tutsplus.com/series/a-guide-to-the-wordpress-theme-customizer--wp-33722
  92. Good articles on modifying the default options:
  93. http://natko.com/changing-default-wordpress-theme-customization-api-sections/
  94. http://code.tutsplus.com/tutorials/digging-into-the-theme-customizer-components--wp-27162
  95. To do:
  96. - Create a js for the postmessage transport method
  97. - Create some sanitize functions to sanitize inputs
  98. - Create some boilerplate Sections, Controls and Settings
  99. */
  100. function bones_theme_customizer($wp_customize) {
  101. // $wp_customize calls go here.
  102. //
  103. // Uncomment the below lines to remove the default customize sections
  104. $wp_customize->remove_section('title_tagline');
  105. $wp_customize->remove_section('colors');
  106. $wp_customize->remove_section('background_image');
  107. $wp_customize->remove_section('static_front_page');
  108. $wp_customize->remove_section('nav');
  109. // Uncomment the below lines to remove the default controls
  110. $wp_customize->remove_control('blogdescription');
  111. // Uncomment the following to change the default section titles
  112. // $wp_customize->get_section('colors')->title = __( 'Theme Colors' );
  113. // $wp_customize->get_section('background_image')->title = __( 'Images' );
  114. }
  115. add_action( 'customize_register', 'bones_theme_customizer' );
  116. /************* ACTIVE SIDEBARS ********************/
  117. // Sidebars & Widgetizes Areas
  118. function bones_register_sidebars() {
  119. register_sidebar(array(
  120. 'id' => 'sidebar1',
  121. 'name' => __( 'Sidebar 1', 'bonestheme' ),
  122. 'description' => __( 'The first (primary) sidebar.', 'bonestheme' ),
  123. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  124. 'after_widget' => '</div>',
  125. 'before_title' => '<h4 class="widgettitle">',
  126. 'after_title' => '</h4>',
  127. ));
  128. /*
  129. to add more sidebars or widgetized areas, just copy
  130. and edit the above sidebar code. In order to call
  131. your new sidebar just use the following code:
  132. Just change the name to whatever your new
  133. sidebar's id is, for example:
  134. register_sidebar(array(
  135. 'id' => 'sidebar2',
  136. 'name' => __( 'Sidebar 2', 'bonestheme' ),
  137. 'description' => __( 'The second (secondary) sidebar.', 'bonestheme' ),
  138. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  139. 'after_widget' => '</div>',
  140. 'before_title' => '<h4 class="widgettitle">',
  141. 'after_title' => '</h4>',
  142. ));
  143. To call the sidebar in your template, you can just copy
  144. the sidebar.php file and rename it to your sidebar's name.
  145. So using the above example, it would be:
  146. sidebar-sidebar2.php
  147. */
  148. } // don't remove this bracket!
  149. /************* COMMENT LAYOUT *********************/
  150. // Comment Layout
  151. function bones_comments( $comment, $args, $depth ) {
  152. $GLOBALS['comment'] = $comment; ?>
  153. <div id="comment-<?php comment_ID(); ?>" <?php comment_class('cf'); ?>>
  154. <article class="cf">
  155. <header class="comment-author vcard">
  156. <?php
  157. /*
  158. this is the new responsive optimized comment image. It used the new HTML5 data-attribute to display comment gravatars on larger screens only. What this means is that on larger posts, mobile sites don't have a ton of requests for comment images. This makes load time incredibly fast! If you'd like to change it back, just replace it with the regular wordpress gravatar call:
  159. echo get_avatar($comment,$size='32',$default='<path_to_url>' );
  160. */
  161. ?>
  162. <?php // custom gravatar call ?>
  163. <?php
  164. // create variable
  165. $bgauthemail = get_comment_author_email();
  166. ?>
  167. <img data-gravatar="http://www.gravatar.com/avatar/<?php echo md5( $bgauthemail ); ?>?s=40" class="load-gravatar avatar avatar-48 photo" height="40" width="40" src="<?php echo get_template_directory_uri(); ?>/library/images/nothing.gif" />
  168. <?php // end custom gravatar call ?>
  169. <?php printf(__( '<cite class="fn">%1$s</cite> %2$s', 'bonestheme' ), get_comment_author_link(), edit_comment_link(__( '(Edit)', 'bonestheme' ),' ','') ) ?>
  170. <time datetime="<?php echo comment_time('Y-m-j'); ?>"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php comment_time(__( 'F jS, Y', 'bonestheme' )); ?> </a></time>
  171. </header>
  172. <?php if ($comment->comment_approved == '0') : ?>
  173. <div class="alert alert-info">
  174. <p><?php _e( 'Your comment is awaiting moderation.', 'bonestheme' ) ?></p>
  175. </div>
  176. <?php endif; ?>
  177. <section class="comment_content cf">
  178. <?php comment_text() ?>
  179. </section>
  180. <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  181. </article>
  182. <?php // </li> is added by WordPress automatically ?>
  183. <?php
  184. } // don't remove this bracket!
  185. /*
  186. This is a modification of a function found in the
  187. twentythirteen theme where we can declare some
  188. external fonts. If you're using Google Fonts, you
  189. can replace these fonts, change it in your scss files
  190. and be up and running in seconds.
  191. */
  192. function bones_fonts() {
  193. wp_enqueue_style('googleFonts', '//fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic');
  194. }
  195. add_action('wp_enqueue_scripts', 'bones_fonts');
  196. // ************************************************************ \\
  197. // ************************************************************ \\
  198. // ************************************************************ \\
  199. // https://blog.teamtreehouse.com/create-your-first-wordpress-custom-post-type
  200. https://developer.wordpress.org/reference/functions/register_post_type/#capability_type
  201. add_action('init', 'mitarbeiter', 0);
  202. function mitarbeiter() {
  203. $labels = array(
  204. 'name' => _x('Mitarbeiter', 'Post Type General Name', 'theme'),
  205. 'singular_name' => _x('Mitarbeiter', 'Post Type Singular Name', 'theme'),
  206. 'menu_name' => __('Mitarbeiter', 'theme'),
  207. 'name_admin_bar' => __('Mitarbeiter', 'theme'),
  208. 'parent_item_colon' => __('Parent Mitarbeiter:', 'theme'),
  209. 'all_items' => __('All Mitarbeiter', 'theme'),
  210. 'add_new_item' => __('Add New Mitarbeiter', 'theme'),
  211. 'add_new' => __('Add New', 'theme'),
  212. 'new_item' => __('New Mitarbeiter', 'theme'),
  213. 'edit_item' => __('Edit Mitarbeiter', 'theme'),
  214. 'update_item' => __('Update Mitarbeiter', 'theme'),
  215. 'view_item' => __('View Mitarbeiter', 'theme'),
  216. 'search_items' => __('Search Mitarbeiter', 'theme'),
  217. 'not_found' => __('Not found', 'theme'),
  218. 'not_found_in_trash' => __('Not found in Trash', 'theme'),
  219. );
  220. $args = array(
  221. 'label' => __('mitarbeiter', 'theme'),
  222. 'labels' => $labels,
  223. 'description' => __('Team', 'theme'),
  224. 'supports' => array('title', 'thumbnail'),
  225. //'taxonomies' => array('category', 'post_tag'),
  226. 'hierarchical' => false,
  227. 'public' => true,
  228. 'show_ui' => true,
  229. 'show_in_menu' => true,
  230. 'menu_position' => 5,
  231. 'show_in_admin_bar' => true,
  232. 'show_in_nav_menus' => true,
  233. 'can_export' => true,
  234. 'has_archive' => true,
  235. 'exclude_from_search' => false,
  236. 'publicly_queryable' => true,
  237. 'capability_type' => 'page',
  238. 'menu_icon' => 'dashicons-id',
  239. );
  240. register_post_type( 'mitarbeiter', $args );
  241. }
  242. add_action('init', 'projekte', 0);
  243. function projekte() {
  244. $labels = array(
  245. 'name' => _x('Projekte', 'Post Type General Name', 'theme'),
  246. 'singular_name' => _x('Projek', 'Post Type Singular Name', 'theme'),
  247. 'menu_name' => __('Projekte', 'theme'),
  248. 'name_admin_bar' => __('Projekte', 'theme'),
  249. 'parent_item_colon' => __('Parent Projekte:', 'theme'),
  250. 'all_items' => __('All Projekte', 'theme'),
  251. 'add_new_item' => __('Add New project', 'theme'),
  252. 'add_new' => __('Add New', 'theme'),
  253. 'new_item' => __('New project', 'theme'),
  254. 'edit_item' => __('Edit project', 'theme'),
  255. 'update_item' => __('Update project', 'theme'),
  256. 'view_item' => __('View projects', 'theme'),
  257. 'search_items' => __('Search projects', 'theme'),
  258. 'not_found' => __('Not found', 'theme'),
  259. 'not_found_in_trash' => __('Not found in Trash', 'theme'),
  260. );
  261. $args = array(
  262. 'label' => __('projekte', 'theme'),
  263. 'labels' => $labels,
  264. 'description' => __('Team', 'theme'),
  265. 'supports' => array('title', 'thumbnail'),
  266. //'taxonomies' => array('category', 'post_tag'),
  267. 'hierarchical' => false,
  268. 'public' => true,
  269. 'show_ui' => true,
  270. 'show_in_menu' => true,
  271. 'menu_position' => 5,
  272. 'show_in_admin_bar' => true,
  273. 'show_in_nav_menus' => true,
  274. 'can_export' => true,
  275. 'has_archive' => true,
  276. 'exclude_from_search' => false,
  277. 'publicly_queryable' => true,
  278. 'capability_type' => 'page',
  279. 'menu_icon' => 'dashicons-store',
  280. );
  281. register_post_type( 'projekte', $args );
  282. }
  283. add_action("admin_init", "admin_init");
  284. function admin_init(){
  285. // mitarbetier
  286. add_meta_box("mitarbeiter-position", "Position", "mitarbeiter_position", "mitarbeiter", "normal", "low");
  287. add_meta_box("mitarbeiter-email", "Email", "mitarbeiter_email", "mitarbeiter", "normal", "low");
  288. // Projekte
  289. add_meta_box("projekt-beschreibung", "Description", "projekt_beschreibung", "projekte", "normal", "low");
  290. add_meta_box("projekt-link", "Link", "projekt_link", "projekte", "normal", "low");
  291. }
  292. function mitarbeiter_email(){
  293. global $post;
  294. $custom = get_post_custom($post->ID);
  295. $mitarbeiter_email = $custom["mitarbeiter_email"][0];
  296. ?>
  297. <label>Email:</label>
  298. <input name="mitarbeiter_email" value="<?php echo $mitarbeiter_email; ?>" />
  299. <?php
  300. }
  301. function mitarbeiter_position(){
  302. global $post;
  303. $custom = get_post_custom($post->ID);
  304. $mitarbeiter_position = $custom["mitarbeiter_position"][0];
  305. ?>
  306. <label>Position:</label>
  307. <input name="mitarbeiter_position" value="<?php echo $mitarbeiter_position; ?>" />
  308. <?php
  309. }
  310. function projekt_beschreibung(){
  311. global $post;
  312. $custom = get_post_custom($post->ID);
  313. $projekt_beschreibung = $custom["projekt_beschreibung"][0];
  314. ?>
  315. <label>Description:</label>
  316. <input name="projekt_beschreibung" value="<?php echo $projekt_beschreibung; ?>" />
  317. <?php
  318. }
  319. function projekt_link(){
  320. global $post;
  321. $custom = get_post_custom($post->ID);
  322. $projekt_link = $custom["projekt_link"][0];
  323. ?>
  324. <label>Link:</label>
  325. <input name="projekt_link" value="<?php echo $projekt_link; ?>" />
  326. <?php
  327. }
  328. add_action('save_post', 'save_details');
  329. function save_details(){
  330. global $post;
  331. // mitarbeiter
  332. update_post_meta($post->ID, "mitarbeiter_position", $_POST["mitarbeiter_position"]);
  333. update_post_meta($post->ID, "mitarbeiter_email", $_POST["mitarbeiter_email"]);
  334. // Projekte
  335. update_post_meta($post->ID, "projekt_beschreibung", $_POST["projekt_beschreibung"]);
  336. update_post_meta($post->ID, "projekt_link", $_POST["projekt_link"]);
  337. }
  338. add_image_size( 'projekt_thumb', 355, 236, true);
  339. /*
  340. Projekte
  341. Baugrupen
  342. Kunden
  343. */
  344. /* DON'T DELETE THIS CLOSING TAG */ ?>