bones.php 13 KB

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