bones.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. /* Welcome to Bones :)
  3. This is the core Bones file where most of the
  4. main functions & features reside. If you have
  5. any custom functions, it's best to put them
  6. in the functions.php file.
  7. Developed by: Eddie Machado
  8. URL: http://themble.com/bones/
  9. */
  10. /*********************
  11. LAUNCH BONES
  12. Let's fire off all the functions
  13. and tools. I put it up here so it's
  14. right up top and clean.
  15. *********************/
  16. // we're firing all out initial functions at the start
  17. add_action('after_setup_theme','bones_ahoy', 15);
  18. function bones_ahoy() {
  19. // launching operation cleanup
  20. add_action('init', 'bones_head_cleanup');
  21. // remove WP version from RSS
  22. add_filter('the_generator', 'bones_rss_version');
  23. // remove pesky injected css for recent comments widget
  24. add_filter( 'wp_head', 'bones_remove_wp_widget_recent_comments_style', 1 );
  25. // clean up comment styles in the head
  26. add_action('wp_head', 'bones_remove_recent_comments_style', 1);
  27. // clean up gallery output in wp
  28. add_filter('gallery_style', 'bones_gallery_style');
  29. // enqueue base scripts and styles
  30. add_action('wp_enqueue_scripts', 'bones_scripts_and_styles', 999);
  31. // launching this stuff after theme setup
  32. add_action('after_setup_theme','bones_theme_support');
  33. // adding sidebars to Wordpress (these are created in functions.php)
  34. add_action( 'widgets_init', 'bones_register_sidebars' );
  35. // adding the bones search form (created in functions.php)
  36. add_filter( 'get_search_form', 'bones_wpsearch' );
  37. // cleaning up random code around images
  38. add_filter('the_content', 'bones_filter_ptags_on_images');
  39. // cleaning up excerpt
  40. add_filter('excerpt_more', 'bones_excerpt_more');
  41. } /* end bones ahoy */
  42. /*********************
  43. WP_HEAD GOODNESS
  44. The default wordpress head is
  45. a mess. Let's clean it up by
  46. removing all the junk we don't
  47. need.
  48. *********************/
  49. function bones_head_cleanup() {
  50. // category feeds
  51. // remove_action( 'wp_head', 'feed_links_extra', 3 );
  52. // post and comment feeds
  53. // remove_action( 'wp_head', 'feed_links', 2 );
  54. // EditURI link
  55. remove_action( 'wp_head', 'rsd_link' );
  56. // windows live writer
  57. remove_action( 'wp_head', 'wlwmanifest_link' );
  58. // index link
  59. remove_action( 'wp_head', 'index_rel_link' );
  60. // previous link
  61. remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
  62. // start link
  63. remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
  64. // links for adjacent posts
  65. remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
  66. // WP version
  67. remove_action( 'wp_head', 'wp_generator' );
  68. } /* end bones head cleanup */
  69. // remove WP version from RSS
  70. function bones_rss_version() { return ''; }
  71. // remove injected CSS for recent comments widget
  72. function bones_remove_wp_widget_recent_comments_style() {
  73. if ( has_filter('wp_head', 'wp_widget_recent_comments_style') ) {
  74. remove_filter('wp_head', 'wp_widget_recent_comments_style' );
  75. }
  76. }
  77. // remove injected CSS from recent comments widget
  78. function bones_remove_recent_comments_style() {
  79. global $wp_widget_factory;
  80. if (isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) {
  81. remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
  82. }
  83. }
  84. // remove injected CSS from gallery
  85. function bones_gallery_style($css) {
  86. return preg_replace("!<style type='text/css'>(.*?)</style>!s", '', $css);
  87. }
  88. /*********************
  89. SCRIPTS & ENQEUEING
  90. *********************/
  91. // loading modernizr and jquery, and reply script
  92. function bones_scripts_and_styles() {
  93. if (!is_admin()) {
  94. // modernizr (without media query polyfill)
  95. wp_register_script( 'bones-modernizr', get_template_directory_uri() . '/library/js/libs/modernizr.custom.min.js', array(), '2.5.3', false );
  96. // register mobile stylesheet
  97. wp_register_style( 'bones-stylesheet', get_template_directory_uri() . '/library/css/style.css', array(), '', 'all' );
  98. // comment reply script for threaded comments
  99. if ( is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) {
  100. wp_enqueue_script( 'comment-reply' );
  101. }
  102. //adding scripts file in the footer
  103. wp_register_script( 'bones-js', get_template_directory_uri() . '/library/js/scripts.js', array( 'jquery' ), '', true );
  104. // enqueue styles and scripts
  105. wp_enqueue_script( 'bones-modernizr' );
  106. wp_enqueue_style( 'bones-stylesheet' );
  107. /*
  108. I reccomend using a plugin to call jQuery
  109. using the google cdn. That way it stays cached
  110. and your site will load faster.
  111. */
  112. wp_enqueue_script( 'jquery' );
  113. wp_enqueue_script( 'bones-js' );
  114. }
  115. }
  116. /*********************
  117. THEME SUPPORT
  118. *********************/
  119. // Adding WP 3+ Functions & Theme Support
  120. function bones_theme_support() {
  121. // wp thumbnails (sizes handled in functions.php)
  122. add_theme_support('post-thumbnails');
  123. // default thumb size
  124. set_post_thumbnail_size(125, 125, true);
  125. // wp custom background
  126. add_custom_background();
  127. // rss thingy
  128. add_theme_support('automatic-feed-links');
  129. // to add header image support go here: http://themble.com/support/adding-header-background-image-support/
  130. // adding post format support
  131. add_theme_support( 'post-formats',
  132. array(
  133. 'aside', // title less blurb
  134. 'gallery', // gallery of images
  135. 'link', // quick link to other site
  136. 'image', // an image
  137. 'quote', // a quick quote
  138. 'status', // a Facebook like status update
  139. 'video', // video
  140. 'audio', // audio
  141. 'chat' // chat transcript
  142. )
  143. );
  144. // wp menus
  145. add_theme_support( 'menus' );
  146. // registering wp3+ menus
  147. register_nav_menus(
  148. array(
  149. 'main_nav' => 'The Main Menu', // main nav in header
  150. 'footer_links' => 'Footer Links' // secondary nav in footer
  151. )
  152. );
  153. } /* end bones theme support */
  154. /*********************
  155. MENUS & NAVIGATION
  156. *********************/
  157. // the main menu
  158. function bones_main_nav() {
  159. // display the wp3 menu if available
  160. wp_nav_menu(array(
  161. 'container' => false, // remove nav container
  162. 'container_class' => 'menu clearfix', // class of container (should you choose to use it)
  163. 'menu' => 'main_nav', // nav name
  164. 'menu_class' => 'nav top-nav clearfix', // adding custom nav class
  165. 'theme_location' => 'main_nav', // where it's located in the theme
  166. 'before' => '', // before the menu
  167. 'after' => '', // after the menu
  168. 'link_before' => '', // before each link
  169. 'link_after' => '', // after each link
  170. 'depth' => 0, // limit the depth of the nav
  171. 'fallback_cb' => 'bones_main_nav_fallback' // fallback function
  172. ));
  173. } /* end bones main nav */
  174. // the footer menu (should you choose to use one)
  175. function bones_footer_links() {
  176. // display the wp3 menu if available
  177. wp_nav_menu(array(
  178. 'container' => '', // remove nav container
  179. 'container_class' => 'footer-links clearfix', // class of container (should you choose to use it)
  180. 'menu' => 'footer_links', // nav name
  181. 'menu_class' => 'nav footer-nav clearfix', // adding custom nav class
  182. 'theme_location' => 'footer_links', // where it's located in the theme
  183. 'before' => '', // before the menu
  184. 'after' => '', // after the menu
  185. 'link_before' => '', // before each link
  186. 'link_after' => '', // after each link
  187. 'depth' => 0, // limit the depth of the nav
  188. 'fallback_cb' => 'bones_footer_links_fallback' // fallback function
  189. ));
  190. } /* end bones footer link */
  191. // this is the fallback for header menu
  192. function bones_main_nav_fallback() {
  193. wp_page_menu( 'show_home=Home' );
  194. }
  195. // this is the fallback for footer menu
  196. function bones_footer_links_fallback() {
  197. /* you can put a default here if you like */
  198. }
  199. /*********************
  200. RELATED POSTS FUNCTION
  201. *********************/
  202. // Related Posts Function (call using bones_related_posts(); )
  203. function bones_related_posts() {
  204. echo '<ul id="bones-related-posts">';
  205. global $post;
  206. $tags = wp_get_post_tags($post->ID);
  207. if($tags) {
  208. foreach($tags as $tag) { $tag_arr .= $tag->slug . ','; }
  209. $args = array(
  210. 'tag' => $tag_arr,
  211. 'numberposts' => 5, /* you can change this to show more */
  212. 'post__not_in' => array($post->ID)
  213. );
  214. $related_posts = get_posts($args);
  215. if($related_posts) {
  216. foreach ($related_posts as $post) : setup_postdata($post); ?>
  217. <li class="related_post"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  218. <?php endforeach; }
  219. else { ?>
  220. <li class="no_related_post">No Related Posts Yet!</li>
  221. <?php }
  222. }
  223. wp_reset_query();
  224. echo '</ul>';
  225. } /* end bones related posts function */
  226. /*********************
  227. PAGE NAVI
  228. *********************/
  229. // Numeric Page Navi (built into the theme by default)
  230. function bones_page_navi($before = '', $after = '') {
  231. global $wpdb, $wp_query;
  232. $request = $wp_query->request;
  233. $posts_per_page = intval(get_query_var('posts_per_page'));
  234. $paged = intval(get_query_var('paged'));
  235. $numposts = $wp_query->found_posts;
  236. $max_page = $wp_query->max_num_pages;
  237. if ( $numposts <= $posts_per_page ) { return; }
  238. if(empty($paged) || $paged == 0) {
  239. $paged = 1;
  240. }
  241. $pages_to_show = 7;
  242. $pages_to_show_minus_1 = $pages_to_show-1;
  243. $half_page_start = floor($pages_to_show_minus_1/2);
  244. $half_page_end = ceil($pages_to_show_minus_1/2);
  245. $start_page = $paged - $half_page_start;
  246. if($start_page <= 0) {
  247. $start_page = 1;
  248. }
  249. $end_page = $paged + $half_page_end;
  250. if(($end_page - $start_page) != $pages_to_show_minus_1) {
  251. $end_page = $start_page + $pages_to_show_minus_1;
  252. }
  253. if($end_page > $max_page) {
  254. $start_page = $max_page - $pages_to_show_minus_1;
  255. $end_page = $max_page;
  256. }
  257. if($start_page <= 0) {
  258. $start_page = 1;
  259. }
  260. echo $before.'<nav class="page-navigation"><ol class="bones_page_navi clearfix">'."";
  261. if ($start_page >= 2 && $pages_to_show < $max_page) {
  262. $first_page_text = "First";
  263. echo '<li class="bpn-first-page-link"><a href="'.get_pagenum_link().'" title="'.$first_page_text.'">'.$first_page_text.'</a></li>';
  264. }
  265. echo '<li class="bpn-prev-link">';
  266. previous_posts_link('<<');
  267. echo '</li>';
  268. for($i = $start_page; $i <= $end_page; $i++) {
  269. if($i == $paged) {
  270. echo '<li class="bpn-current">'.$i.'</li>';
  271. } else {
  272. echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
  273. }
  274. }
  275. echo '<li class="bpn-next-link">';
  276. next_posts_link('>>');
  277. echo '</li>';
  278. if ($end_page < $max_page) {
  279. $last_page_text = "Last";
  280. echo '<li class="bpn-last-page-link"><a href="'.get_pagenum_link($max_page).'" title="'.$last_page_text.'">'.$last_page_text.'</a></li>';
  281. }
  282. echo '</ol></nav>'.$after."";
  283. } /* end page navi */
  284. /*********************
  285. RANDOM CLEANUP ITEMS
  286. *********************/
  287. // remove the p from around imgs (http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/)
  288. function bones_filter_ptags_on_images($content){
  289. return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
  290. }
  291. // This removes the annoying […] to a Read More link
  292. function bones_excerpt_more($more) {
  293. global $post;
  294. // edit here if you like
  295. return '... <a href="'. get_permalink($post->ID) . '" title="Read '.get_the_title($post->ID).'">Read more &raquo;</a>';
  296. }
  297. ?>