PageRenderTime 89ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/public/wp-content/themes/illiench/functions.php

https://bitbucket.org/millien/illien.ch-wordpress
PHP | 306 lines | 198 code | 79 blank | 29 comment | 26 complexity | 7cf3825151e66ba150a1013bca0564dc MD5 | raw file
  1. <?php
  2. if ( ! isset( $content_width ) )
  3. $content_width = 787;
  4. /*-----------------------------------------------------------------------------------
  5. - Start Themnific Functions - Please refrain from editing this section
  6. ----------------------------------------------------------------------------------- */
  7. // Set path to Themnific Framework and theme specific functions
  8. $functions_path = get_template_directory() . '/functions/';
  9. $includes_path = get_template_directory() . '/functions/';
  10. // Framework
  11. require_once ($functions_path . 'admin-init.php'); // Framework Init
  12. // Theme specific functionality
  13. require_once ($includes_path . 'theme-options.php'); // Options panel settings and custom settings
  14. require_once ($includes_path . 'theme-actions.php'); // Theme actions & user defined hooks
  15. require_once ($includes_path . 'theme-scripts.php'); // Load JavaScript via wp_enqueue_script
  16. //Add Custom Post Types
  17. require_once ($includes_path . 'posttypes/ptype-portfolio.php'); // portfolio post type
  18. require_once ($includes_path . 'posttypes/ptype-layout.php'); // layout post type
  19. require_once ($includes_path . 'posttypes/ptype-slider.php'); // slider post type
  20. require_once ($includes_path . 'posttypes/ptype-services.php'); // services post type
  21. require_once ($includes_path . 'posttypes/ptype-clients.php'); // clients post type
  22. require_once ($includes_path . 'posttypes/ptype-pricing-tabs.php'); // pricing tabs post type
  23. require_once ($includes_path . 'posttypes/post-metabox.php'); // custom meta box
  24. /*-----------------------------------------------------------------------------------
  25. - Loads all the .php files found in /admin/widgets/ directory
  26. ----------------------------------------------------------------------------------- */
  27. $preview_template = _preview_theme_template_filter();
  28. if(!empty($preview_template)){
  29. $widgets_dir = WP_CONTENT_DIR . "/themes/".$preview_template."/functions/widgets/";
  30. } else {
  31. $widgets_dir = WP_CONTENT_DIR . "/themes/".get_option('template')."/functions/widgets/";
  32. }
  33. if (@is_dir($widgets_dir)) {
  34. $widgets_dh = opendir($widgets_dir);
  35. while (($widgets_file = readdir($widgets_dh)) !== false) {
  36. if(strpos($widgets_file,'.php') && $widgets_file != "widget-blank.php") {
  37. include_once($widgets_dir . $widgets_file);
  38. }
  39. }
  40. closedir($widgets_dh);
  41. }
  42. // Post thumbnail support
  43. if (function_exists('add_theme_support')) {
  44. add_theme_support('post-thumbnails');
  45. set_post_thumbnail_size(640, 265, true); // Normal post thumbnails
  46. // first try
  47. add_image_size('block_1', 320, 200, true ); //(cropped)
  48. add_image_size('block_2', 428, 400, true ); //(cropped)
  49. add_image_size('block_3', 212, 200, true ); //(cropped)
  50. add_image_size('block_4', 428, 200, true ); //(cropped)
  51. add_image_size('block_5', 320, 400, true ); //(cropped)
  52. add_image_size('format-gallery', 622, 400, true);
  53. add_image_size('format-image', 622, 9999);
  54. add_image_size('format-single', 622, 220, true); //(cropped)
  55. add_image_size('folio', 300, 230, true ); //(cropped)
  56. add_image_size('folio_slider', 960, 450, true ); //(cropped)
  57. add_image_size('clients', 239, 200, true); //(cropped)
  58. add_image_size('tabs', 50, 40, true); //(cropped)
  59. }
  60. function thumb_url(){
  61. $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 2100,2100 ));
  62. return $src[0];
  63. }
  64. // Add Theme Support Functions
  65. add_editor_style();
  66. add_theme_support( 'post-formats', array( 'video','audio', 'gallery', 'image', 'quote', 'link' ) );
  67. add_theme_support( 'automatic-feed-links' );
  68. add_theme_support( 'custom-background' );
  69. // widgets
  70. if ( function_exists('register_sidebar') )
  71. {
  72. // sidebar widget
  73. register_sidebar(array('name' => 'Sidebar','before_widget' => '','after_widget' => '','before_title' => '<h2>','after_title' => '</h2>'));
  74. }
  75. // Make theme available for translation
  76. load_theme_textdomain( 'themnific', get_template_directory() . '/lang' );
  77. // Shordcodes
  78. require_once (get_template_directory().'/functions/admin-shortcodes.php' ); // Shortcodes
  79. require_once (get_template_directory().'/functions/admin-shortcode-generator.php' ); // Shortcode generator
  80. // Use shortcodes in text widgets.
  81. add_filter('widget_text', 'do_shortcode');
  82. // navigation menu
  83. function register_main_menus() {
  84. register_nav_menus(
  85. array(
  86. 'home-menu' => "Home Menu" ,
  87. 'main-menu' => "Main Menu"
  88. )
  89. );
  90. };
  91. if (function_exists('register_nav_menus')) add_action( 'init', 'register_main_menus' );
  92. // Shorten post title
  93. function short_title($after = '', $length) {
  94. $mytitle = explode(' ', get_the_title(), $length);
  95. if (count($mytitle)>=$length) {
  96. array_pop($mytitle);
  97. $mytitle = implode(" ",$mytitle). $after;
  98. } else {
  99. $mytitle = implode(" ",$mytitle);
  100. }
  101. return $mytitle;
  102. }
  103. // icons - font awesome
  104. function tmnf_icon() {
  105. if(has_post_format('video')) {return '<i class="icon-play-circle"></i>';
  106. }elseif(has_post_format('audio')) {return '<i class="icon-music"></i>';
  107. }elseif(has_post_format('gallery')) {return '<i class="icon-picture"></i>';
  108. }elseif(has_post_format('link')) {return '<i class="icon-signout"></i>';
  109. }elseif(has_post_format('image')) {return '<i class="icon-camera"></i>';
  110. }elseif(has_post_format('quote')) {return '<i class="icon-quote-right"></i>';
  111. } else {'';}
  112. }
  113. // icons ribbons - font awesome
  114. function tmnf_ribbon() {
  115. if(has_post_format('video')) {return '<span class="ribbon"></span><span class="ribbon_icon"><i class="icon-play-circle"></i></span>';
  116. }elseif(has_post_format('audio')) {return '<span class="ribbon"></span><span class="ribbon_icon"><i class="icon-music"></i></span>';
  117. }elseif(has_post_format('gallery')) {return '<span class="ribbon"></span><span class="ribbon_icon"><i class="icon-picture"></i></span>';
  118. }elseif(has_post_format('link')) {return '<span class="ribbon"></span><span class="ribbon_icon"><i class="icon-signout"></i></span>';
  119. }elseif(has_post_format('image')) {return '<span class="ribbon"></span><span class="ribbon_icon"><i class="icon-camera"></i></span>';
  120. }elseif(has_post_format('quote')) {return '<span class="ribbon"></span><span class="ribbon_icon"><i class="icon-quote-right"></i></span>';
  121. } else {'';}
  122. }
  123. // managed excerpt
  124. function tmnf_excerptlength_teaser($length) {
  125. return 90;
  126. }
  127. function tmnf_excerptlength_index($length) {
  128. return 13;
  129. }
  130. function tmnf_excerptmore($more) {
  131. return '...';
  132. }
  133. add_filter( 'wp_get_attachment_link', 'gallery_prettyPhoto');
  134. // new excerpt function
  135. function tmnf_excerpt($length_callback='', $more_callback='') {
  136. global $post;
  137. if(function_exists($length_callback)){
  138. add_filter('excerpt_length', $length_callback);
  139. }
  140. if(function_exists($more_callback)){
  141. add_filter('excerpt_more', $more_callback);
  142. }
  143. $output = get_the_excerpt();
  144. $output = apply_filters('wptexturize', $output);
  145. $output = apply_filters('convert_chars', $output);
  146. $output = '<p>'.$output.'</p>';
  147. echo $output;
  148. }
  149. // Old Shorten Excerpt text for use in theme
  150. function themnific_excerpt($text, $chars = 1620) {
  151. $text = $text." ";
  152. $text = substr($text,0,$chars);
  153. $text = substr($text,0,strrpos($text,' '));
  154. $text = $text."...";
  155. return $text;
  156. }
  157. function trim_excerpt($text) {
  158. return rtrim($text,'[...]');
  159. }
  160. add_filter('get_the_excerpt', 'trim_excerpt');
  161. // automatically add prettyPhoto rel attributes to embedded images
  162. function gallery_prettyPhoto ($content) {
  163. // add checks if you want to add prettyPhoto on certain places (archives etc).
  164. return str_replace("<a", "<a rel='prettyPhoto[gallery]'", $content);
  165. }
  166. function insert_prettyPhoto_rel($content) {
  167. $pattern = '/<a(.*?)href="(.*?).(bmp|gif|jpeg|jpg|png)"(.*?)>/i';
  168. $replacement = '<a$1href="$2.$3" rel=\'prettyPhoto\'$4>';
  169. $content = preg_replace( $pattern, $replacement, $content );
  170. return $content;
  171. }
  172. add_filter( 'the_content', 'insert_prettyPhoto_rel' );
  173. // pagination
  174. function pagination($prev = '&laquo;', $next = '&raquo;') {
  175. global $wp_query, $wp_rewrite;
  176. $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
  177. $pagination = array(
  178. 'base' => @add_query_arg('paged','%#%'),
  179. 'format' => '',
  180. 'total' => $wp_query->max_num_pages,
  181. 'current' => $current,
  182. 'prev_text' => __('Previous','themnific'),
  183. 'next_text' => __('Next','themnific'),
  184. 'type' => 'plain'
  185. );
  186. if( $wp_rewrite->using_permalinks() )
  187. $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
  188. if( !empty($wp_query->query_vars['s']) )
  189. $pagination['add_args'] = array( 's' => get_query_var( 's' ) );
  190. echo paginate_links( $pagination );
  191. };
  192. //Breadcrumbs
  193. function the_breadcrumb() {
  194. if (!is_home()) {
  195. echo '<a href="'. home_url().'">';
  196. echo '<i class="icon-home"></i> ';
  197. echo "</a> &raquo; ";
  198. if (is_category() || is_single()) {
  199. the_category(', ');
  200. if (is_single()) {
  201. echo " &raquo; ";
  202. echo short_title('...', 6);
  203. }
  204. } elseif (is_page()) {
  205. echo the_title();}
  206. }
  207. }
  208. function attachment_toolbox($size = thumbnail) {
  209. if($images = get_children(array(
  210. 'post_parent' => get_the_ID(),
  211. 'post_type' => 'attachment',
  212. 'numberposts' => -1, // show all
  213. 'post_status' => null,
  214. 'post_mime_type' => 'image',
  215. ))) {
  216. foreach($images as $image) {
  217. $attimg = wp_get_attachment_image($image->ID,$size);
  218. $atturl = wp_get_attachment_url($image->ID);
  219. $attlink = get_attachment_link($image->ID);
  220. $postlink = get_permalink($image->post_parent);
  221. $atttitle = apply_filters('the_title',$image->post_title);
  222. echo '<p><strong>wp_get_attachment_image()</strong><br />'.$attimg.'</p>';
  223. echo '<p><strong>wp_get_attachment_url()</strong><br />'.$atturl.'</p>';
  224. }
  225. }
  226. }
  227. ?>