/functions/inkthemes-functions.php

  1. <?php 
  2.  
  3. function inkthemes_setup() { 
  4. /** ----------------------------------------------------------------------------------- */ 
  5. /** Theme Support 
  6. /**----------------------------------------------------------------------------------- */ 
  7. add_theme_support('post-thumbnails'); 
  8. add_image_size('post-thumbnails', 216, 168, true); 
  9. //custom background support 
  10. add_theme_support('custom-background', array( 
  11. // Background color default 
  12. 'default-color' => '000',  
  13. // Background image default 
  14. //'default-image' => get_template_directory_uri() . '/images/body-bg.png' 
  15. )); 
  16. $args = array( 
  17. 'width' => 1920,  
  18. 'height' => 654,  
  19. 'flex-height' => true,  
  20. 'flex-width' => true,  
  21. 'header-text' => false,  
  22. 'default-image' => get_template_directory_uri() . '/images/slider-1.jpg',  
  23. ); 
  24. //custom header support 
  25. add_theme_support('custom-header', $args); 
  26. /** ----------------------------------------------------------------------------------- */ 
  27. /** Auto Feed Links Support 
  28. /**----------------------------------------------------------------------------------- */ 
  29. add_theme_support('automatic-feed-links'); 
  30. //Load languages file 
  31. load_theme_textdomain('blcr', get_template_directory() . '/languages'); 
  32. $locale = get_locale(); 
  33. $locale_file = get_stylesheet_directory_uri() . "/languages/$locale.php"; 
  34. if (is_readable($locale_file)) 
  35. require_once($locale_file); 
  36. // This theme styles the visual editor with editor-style.css to match the theme style. 
  37. add_editor_style(); 
  38. // activate support for thumbnails 
  39. // added in 2.9 
  40. add_theme_support('menus'); 
  41. set_post_thumbnail_size(216, 168, false); 
  42.  
  43. add_action('after_setup_theme', 'inkthemes_setup'); 
  44. /** ----------------------------------------------------------------------------------- */ 
  45. /** Custom Menus Function 
  46. /**----------------------------------------------------------------------------------- */ 
  47.  
  48. // Add CLASS attributes to the first <ul> occurence in wp_page_menu 
  49. function inkthemes_add_menuclass($ulclass) { 
  50. return preg_replace('/<ul>/', '<ul class="ddsmoothmenu">', $ulclass, 1); 
  51.  
  52. add_filter('wp_page_menu', 'inkthemes_add_menuclass'); 
  53. add_action('after_setup_theme', 'inkthemes_register_custom_menu'); 
  54.  
  55. function inkthemes_register_custom_menu() { 
  56. register_nav_menu('custom_menu', __('Main Menu', 'blcr')); 
  57.  
  58. function inkthemes_nav() { 
  59. if (function_exists('wp_nav_menu')) 
  60. wp_nav_menu(array('theme_location' => 'custom_menu', 'container_id' => 'menu', 'menu_class' => 'ddsmoothmenu', 'fallback_cb' => 'inkthemes_nav_fallback')); 
  61. else 
  62. inkthemes_nav_fallback(); 
  63.  
  64. function inkthemes_nav_fallback() { 
  65. ?> 
  66. <div id="menu"> 
  67. <ul class="ddsmoothmenu"> 
  68. <?php 
  69. wp_list_pages('title_li=&show_home=1&sort_column=menu_order'); 
  70. ?> 
  71. </ul> 
  72. </div> 
  73. <?php 
  74.  
  75. function inkthemes_nav_menu_items($items) { 
  76. if (is_home()) { 
  77. $homelink = '<li class="current_page_item">' . '<a href="' . home_url('/') . '">' . __('Home', 'road-fighter') . '</a></li>'; 
  78. } else { 
  79. $homelink = '<li>' . '<a href="' . home_url('/') . '">' . __('Home', 'road-fighter') . '</a></li>'; 
  80. $items = $homelink . $items; 
  81. return $items; 
  82.  
  83. add_filter('wp_list_pages', 'inkthemes_nav_menu_items'); 
  84. /** ----------------------------------------------------------------------------------- */ 
  85. /** Breadcrumbs Plugin 
  86. /**----------------------------------------------------------------------------------- */ 
  87.  
  88. function inkthemes_breadcrumbs() { 
  89. $delimiter = '»'; 
  90. $home = 'Home'; // text for the 'Home' link 
  91. $before = '<span class="current">'; // tag before the current crumb 
  92. $after = '</span>'; // tag after the current crumb 
  93. echo '<div id="crumbs">'; 
  94. global $post; 
  95. $homeLink = home_url(); 
  96. echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' '; 
  97. if (is_category()) { 
  98. global $wp_query; 
  99. $cat_obj = $wp_query->get_queried_object(); 
  100. $thisCat = $cat_obj->term_id; 
  101. $thisCat = get_category($thisCat); 
  102. $parentCat = get_category($thisCat->parent); 
  103. if ($thisCat->parent != 0) 
  104. echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' ')); 
  105. echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after; 
  106. elseif (is_day()) { 
  107. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; 
  108. echo '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' '; 
  109. echo $before . get_the_time('d') . $after; 
  110. } elseif (is_month()) { 
  111. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; 
  112. echo $before . get_the_time('F') . $after; 
  113. } elseif (is_year()) { 
  114. echo $before . get_the_time('Y') . $after; 
  115. } elseif (is_single() && !is_attachment()) { 
  116. if (get_post_type() != 'post') { 
  117. $post_type = get_post_type_object(get_post_type()); 
  118. $slug = $post_type->rewrite; 
  119. echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' '; 
  120. echo $before . get_the_title() . $after; 
  121. } else { 
  122. $cat = get_the_category(); 
  123. $cat = $cat[0]; 
  124. echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); 
  125. echo $before . get_the_title() . $after; 
  126. } elseif (!is_single() && !is_page() && get_post_type() != 'post') { 
  127. $post_type = get_post_type_object(get_post_type()); 
  128. echo $before . $post_type->labels->singular_name . $after; 
  129. } elseif (is_attachment()) { 
  130. $parent = get_post($post->post_parent); 
  131. $cat = get_the_category($parent->ID); 
  132. $cat = $cat[0]; 
  133. echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); 
  134. echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' '; 
  135. echo $before . get_the_title() . $after; 
  136. } elseif (is_page() && !$post->post_parent) { 
  137. echo $before . get_the_title() . $after; 
  138. } elseif (is_page() && $post->post_parent) { 
  139. $parent_id = $post->post_parent; 
  140. $breadcrumbs = array(); 
  141. while ($parent_id) { 
  142. $page = get_page($parent_id); 
  143. $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>'; 
  144. $parent_id = $page->post_parent; 
  145. $breadcrumbs = array_reverse($breadcrumbs); 
  146. foreach ($breadcrumbs as $crumb) 
  147. echo $crumb . ' ' . $delimiter . ' '; 
  148. echo $before . get_the_title() . $after; 
  149. } elseif (is_search()) { 
  150. echo $before . 'Search results for "' . get_search_query() . '"' . $after; 
  151. } elseif (is_tag()) { 
  152. echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after; 
  153. } elseif (is_author()) { 
  154. global $author; 
  155. $userdata = get_userdata($author); 
  156. echo $before . 'Articles posted by ' . $userdata->display_name . $after; 
  157. } elseif (is_404()) { 
  158. echo $before . 'Error 404' . $after; 
  159. if (get_query_var('paged')) { 
  160. if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) 
  161. echo ' ('; 
  162. echo __('Page', 'road-fighter') . ' ' . get_query_var('paged'); 
  163. if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author()) 
  164. echo ')'; 
  165. echo '</div>'; 
  166.  
  167. /** 
  168. * This function gets image width and height and 
  169. * Prints attached images from the post  
  170. */ 
  171. function inkthemes_get_image($width, $height) { 
  172. $w = $width; 
  173. $h = $height; 
  174. global $post, $posts; 
  175. //This is required to set to Null 
  176. $img_source = ''; 
  177. $id = ''; 
  178. $permalink = get_permalink(); 
  179. ob_start(); 
  180. ob_end_clean(); 
  181. $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); 
  182. if (isset($matches [1] [0])) { 
  183. $img_source = $matches [1] [0]; 
  184. if ($img_source) { 
  185. print "<div class='post-image'><a href='$permalink'><span></span></a><img height='$h' width='$w' src='$img_path[url]' class='postimg' alt='Post Image'/></div>"; 
  186.  
  187. /** ----------------------------------------------------------------------------------- */ 
  188. /** Attachment Page Design 
  189. /**----------------------------------------------------------------------------------- */ 
  190.  
  191. //For Attachment Page 
  192. /** 
  193. * Prints HTML with meta information for the current post (category, tags and permalink). 
  194. * 
  195. */ 
  196. function inkthemes_posted_in() { 
  197. // Retrieves tag list of current post, separated by commas. 
  198. $tag_list = get_the_tag_list('', ', '); 
  199. if ($tag_list) { 
  200. $posted_in = POSTED_ENTRY; 
  201. } elseif (is_object_in_taxonomy(get_post_type(), 'category')) { 
  202. $posted_in = POSTED_BOOKMARK; 
  203. } else { 
  204. $posted_in = BOOKMARK; 
  205. // Prints the string, replacing the placeholders. 
  206. printf( 
  207. $posted_in, get_the_category_list(', '), $tag_list, get_permalink(), the_title_attribute('echo=0') 
  208. ); 
  209.  
  210. /** 
  211. * Set the content width based on the theme's design and stylesheet. 
  212. * 
  213. * Used to set the width of images and content. Should be equal to the width the theme 
  214. * is designed for, generally via the style.css stylesheet. 
  215. */ 
  216. if (!isset($content_width)) 
  217. $content_width = 590; 
  218. ?> 
  219. <?php 
  220.  
  221. /** 
  222. * Register widgetized areas, including two sidebars and four widget-ready columns in the footer. 
  223. * 
  224. * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own 
  225. * function tied to the init hook. 
  226. * 
  227. * @uses register_sidebar 
  228. */ 
  229. function inkthemes_widgets_init() { 
  230. // Area 1, located at the top of the sidebar. 
  231. register_sidebar(array( 
  232. 'name' => PRIMARY_WIDGET,  
  233. 'id' => 'primary-widget-area',  
  234. 'description' => THE_PRIMARY_WIDGET,  
  235. 'before_widget' => '',  
  236. 'after_widget' => '',  
  237. 'before_title' => '<h3>',  
  238. 'after_title' => '</h3>',  
  239. )); 
  240. // Area 2, located below the Primary Widget Area in the sidebar. Empty by default. 
  241. register_sidebar(array( 
  242. 'name' => SECONDRY_WIDGET,  
  243. 'id' => 'secondary-widget-area',  
  244. 'description' => THE_SECONDRY_WIDGET,  
  245. 'before_widget' => '',  
  246. 'after_widget' => '',  
  247. 'before_title' => '<h3>',  
  248. 'after_title' => '</h3>',  
  249. )); 
  250. // Area 2, located below the Primary Widget Area in the sidebar. Empty by default. 
  251. register_sidebar(array( 
  252. 'name' => RIGHT_WIDGET,  
  253. 'id' => 'home-page-widget-area',  
  254. 'description' => THE_RIGHT_WIDGET,  
  255. 'before_widget' => '',  
  256. 'after_widget' => '',  
  257. 'before_title' => '<h3>',  
  258. 'after_title' => '</h3>',  
  259. )); 
  260. // Area 3, located in the footer. Empty by default. 
  261. register_sidebar(array( 
  262. 'name' => FIRST_FOOTER_WIDGET,  
  263. 'id' => 'first-footer-widget-area',  
  264. 'description' => THE_FIRST_FOOTER_WIDGET,  
  265. 'before_widget' => '',  
  266. 'after_widget' => '',  
  267. 'before_title' => '<h3>',  
  268. 'after_title' => '</h3>',  
  269. )); 
  270. // Area 4, located in the footer. Empty by default. 
  271. register_sidebar(array( 
  272. 'name' => SECONDRY_FOOTER_WIDGET,  
  273. 'id' => 'second-footer-widget-area',  
  274. 'description' => THE_SECONDRY_FOOTER_WIDGET,  
  275. 'before_widget' => '',  
  276. 'after_widget' => '',  
  277. 'before_title' => '<h3>',  
  278. 'after_title' => '</h3>',  
  279. )); 
  280. // Area 5, located in the footer. Empty by default. 
  281. register_sidebar(array( 
  282. 'name' => THIRD_FOOTER_WIDGET,  
  283. 'id' => 'third-footer-widget-area',  
  284. 'description' => THE_THIRD_FOOTER_WIDGET,  
  285. 'before_widget' => '',  
  286. 'after_widget' => '',  
  287. 'before_title' => '<h3>',  
  288. 'after_title' => '</h3>',  
  289. )); 
  290. // Area 6, located in the footer. Empty by default. 
  291. register_sidebar(array( 
  292. 'name' => FOURTH_FOOTER_WIDGET,  
  293. 'id' => 'fourth-footer-widget-area',  
  294. 'description' => THE_FOURTH_FOOTER_WIDGET,  
  295. 'before_widget' => '',  
  296. 'after_widget' => '',  
  297. 'before_title' => '<h3>',  
  298. 'after_title' => '</h3>',  
  299. )); 
  300.  
  301. /** Register sidebars by running inkthemes_widgets_init() on the widgets_init hook. */ 
  302. add_action('widgets_init', 'inkthemes_widgets_init'); 
  303.  
  304. /** 
  305. * Pagination 
  306. * 
  307. */ 
  308. function inkthemes_pagination($pages = '', $range = 2) { 
  309. $showitems = ($range * 2) + 1; 
  310. global $paged; 
  311. if (empty($paged)) 
  312. $paged = 1; 
  313. if ($pages == '') { 
  314. global $wp_query; 
  315. $pages = $wp_query->max_num_pages; 
  316. if (!$pages) { 
  317. $pages = 1; 
  318. if (1 != $pages) { 
  319. echo "<ul class='paging'>"; 
  320. if ($paged > 2 && $paged > $range + 1 && $showitems < $pages) 
  321. echo "<li><a href='" . get_pagenum_link(1) . "'>«</a></li>"; 
  322. if ($paged > 1 && $showitems < $pages) 
  323. echo "<li><a href='" . get_pagenum_link($paged - 1) . "'>‹</a></li>"; 
  324. for ($i = 1; $i <= $pages; $i++) { 
  325. if (1 != $pages && (!($i >= $paged + $range + 1 || $i <= $paged - $range - 1) || $pages <= $showitems )) { 
  326. echo ($paged == $i) ? "<li><a href='" . get_pagenum_link($i) . "' class='current' >" . $i . "</a></li>" : "<li><a href='" . get_pagenum_link($i) . "' class='inactive' >" . $i . "</a></li>"; 
  327. if ($paged < $pages && $showitems < $pages) 
  328. echo "<li><a href='" . get_pagenum_link($paged + 1) . "'>›</a></li>"; 
  329. if ($paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages) 
  330. echo "<li><a href='" . get_pagenum_link($pages) . "'>»</a></li>"; 
  331. echo "</ul>\n"; 
  332.  
  333. /////////Theme Options 
  334. /** ----------------------------------------------------------------------------------- */ 
  335. /** Add Favicon 
  336. /**----------------------------------------------------------------------------------- */ 
  337. function inkthemes_childtheme_favicon() { 
  338. if (inkthemes_get_option('inkthemes_favicon') != '') { 
  339. echo '<link rel="shortcut icon" href="' . inkthemes_get_option('inkthemes_favicon') . '"/>' . "\n"; 
  340. } else { 
  341. ?> 
  342. <link rel="shortcut icon" href="<?php echo get_template_directory_uri() ?>/images/favicon.ico" /> 
  343. <?php 
  344.  
  345. add_action('wp_head', 'inkthemes_childtheme_favicon'); 
  346. /** ----------------------------------------------------------------------------------- */ 
  347. /** Show analytics code in footer */ 
  348. /** ----------------------------------------------------------------------------------- */ 
  349.  
  350. function inkthemes_childtheme_analytics() { 
  351. $output = inkthemes_get_option('inkthemes_analytics'); 
  352. if ($output <> "") 
  353. echo stripslashes($output); 
  354.  
  355. add_action('wp_head', 'inkthemes_childtheme_analytics'); 
  356. /** ----------------------------------------------------------------------------------- */ 
  357. /** Custom CSS Styles */ 
  358. /** ----------------------------------------------------------------------------------- */ 
  359.  
  360. function inkthemes_of_head_css() { 
  361. $output = ''; 
  362. $custom_css = inkthemes_get_option('inkthemes_customcss'); 
  363. if ($custom_css <> '') { 
  364. $output .= $custom_css . "\n"; 
  365. // Output styles 
  366. if ($output <> '') { 
  367. $output = "<!-- Custom Styling -->\n<style type=\"text/css\">\n" . $output . "</style>\n"; 
  368. echo $output; 
  369.  
  370. add_action('wp_head', 'inkthemes_of_head_css'); 
  371.  
  372. // activate support for thumbnails 
  373. function inkthemes_get_category_id($cat_name) { 
  374. $term = get_term_by('name', $cat_name, 'category'); 
  375. return $term->term_id; 
  376.  
  377. //Trm excerpt 
  378. function inkthemes_trim_excerpt($length) { 
  379. global $post; 
  380. $explicit_excerpt = $post->post_excerpt; 
  381. if ('' == $explicit_excerpt) { 
  382. $text = get_the_content(''); 
  383. $text = apply_filters('the_content', $text); 
  384. $text = str_replace(']]>', ']]>', $text); 
  385. } else { 
  386. $text = apply_filters('the_content', $explicit_excerpt); 
  387. $text = strip_shortcodes($text); // optional 
  388. $text = strip_tags($text); 
  389. $excerpt_length = $length; 
  390. $words = explode(' ', $text, $excerpt_length + 1); 
  391. if (count($words) > $excerpt_length) { 
  392. array_pop($words); 
  393. array_push($words, '[…]'); 
  394. $text = implode(' ', $words); 
  395. $text = apply_filters('the_excerpt', $text); 
  396. return $text; 
  397.  
  398. function inkthemes_image_post($post_id) { 
  399. add_post_meta($post_id, 'img_key', 'on'); 
  400.  
  401. //Trm post title 
  402. function inkthemes_titlesmall($before = '', $after = '', $echo = true, $length = false) { 
  403. $title = get_the_title(); 
  404. if ($length && is_numeric($length)) { 
  405. $title = substr($title, 0, $length); 
  406. if (strlen($title) > 0) { 
  407. $title = apply_filters('inkthemes_titlesmall', $before . $title . $after, $before, $after); 
  408. if ($echo) 
  409. echo $title; 
  410. else 
  411. return $title; 
  412.  
  413. add_filter( 'wp_title', 'inkthemes_wp_title' ); 
  414. /** 
  415. * Filters the page title appropriately depending on the current page 
  416. * 
  417. * This function is attached to the 'wp_title' fiilter hook. 
  418. * 
  419. * @uses get_bloginfo() 
  420. * @uses is_home() 
  421. * @uses is_front_page() 
  422. */ 
  423. function inkthemes_wp_title( $title ) { 
  424. global $page, $paged; 
  425.  
  426. if ( is_feed() ) 
  427. return $title; 
  428.  
  429. $site_description = get_bloginfo( 'description' ); 
  430.  
  431. $filtered_title = $title . get_bloginfo( 'name' ); 
  432. $filtered_title .= ( ! empty( $site_description ) && ( is_home() || is_front_page() ) ) ? ' | ' . $site_description: ''; 
  433. $filtered_title .= ( 2 <= $paged || 2 <= $page ) ? ' | ' . sprintf( __( 'Page %s', 'blcr' ), max( $paged, $page ) ) : ''; 
  434.  
  435. return $filtered_title; 
  436. ?> 
.