bones.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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 (thx to @bransonwerner for update)
  126. add_theme_support( 'custom-background',
  127. array(
  128. 'default-image' => '', // background image default
  129. 'default-color' => '', // background color default (dont add the #)
  130. 'wp-head-callback' => '_custom_background_cb',
  131. 'admin-head-callback' => '',
  132. 'admin-preview-callback' => ''
  133. )
  134. );
  135. // rss thingy
  136. add_theme_support('automatic-feed-links');
  137. // to add header image support go here: http://themble.com/support/adding-header-background-image-support/
  138. // adding post format support
  139. add_theme_support( 'post-formats',
  140. array(
  141. 'aside', // title less blurb
  142. 'gallery', // gallery of images
  143. 'link', // quick link to other site
  144. 'image', // an image
  145. 'quote', // a quick quote
  146. 'status', // a Facebook like status update
  147. 'video', // video
  148. 'audio', // audio
  149. 'chat' // chat transcript
  150. )
  151. );
  152. // wp menus
  153. add_theme_support( 'menus' );
  154. // registering wp3+ menus
  155. register_nav_menus(
  156. array(
  157. 'main-nav' => _e( 'The Main Menu' ), // main nav in header
  158. 'footer-links' => _e( 'Footer Links' ) // secondary nav in footer
  159. )
  160. );
  161. } /* end bones theme support */
  162. /*********************
  163. MENUS & NAVIGATION
  164. *********************/
  165. // the main menu
  166. function bones_main_nav() {
  167. // display the wp3 menu if available
  168. wp_nav_menu(array(
  169. 'container' => false, // remove nav container
  170. 'container_class' => 'menu clearfix', // class of container (should you choose to use it)
  171. 'menu' => 'The Main Menu', // nav name
  172. 'menu_class' => 'nav top-nav clearfix', // adding custom nav class
  173. 'theme_location' => 'main-nav', // where it's located in the theme
  174. 'before' => '', // before the menu
  175. 'after' => '', // after the menu
  176. 'link_before' => '', // before each link
  177. 'link_after' => '', // after each link
  178. 'depth' => 0, // limit the depth of the nav
  179. 'fallback_cb' => 'bones_main_nav_fallback' // fallback function
  180. ));
  181. } /* end bones main nav */
  182. // the footer menu (should you choose to use one)
  183. function bones_footer_links() {
  184. // display the wp3 menu if available
  185. wp_nav_menu(array(
  186. 'container' => '', // remove nav container
  187. 'container_class' => 'footer-links clearfix', // class of container (should you choose to use it)
  188. 'menu' => 'Footer Links', // nav name
  189. 'menu_class' => 'nav footer-nav clearfix', // adding custom nav class
  190. 'theme_location' => 'footer-links', // where it's located in the theme
  191. 'before' => '', // before the menu
  192. 'after' => '', // after the menu
  193. 'link_before' => '', // before each link
  194. 'link_after' => '', // after each link
  195. 'depth' => 0, // limit the depth of the nav
  196. 'fallback_cb' => 'bones_footer_links_fallback' // fallback function
  197. ));
  198. } /* end bones footer link */
  199. // this is the fallback for header menu
  200. function bones_main_nav_fallback() {
  201. wp_page_menu( 'show_home=Home' );
  202. }
  203. // this is the fallback for footer menu
  204. function bones_footer_links_fallback() {
  205. /* you can put a default here if you like */
  206. }
  207. /*********************
  208. RELATED POSTS FUNCTION
  209. *********************/
  210. // Related Posts Function (call using bones_related_posts(); )
  211. function bones_related_posts() {
  212. echo '<ul id="bones-related-posts">';
  213. global $post;
  214. $tags = wp_get_post_tags($post->ID);
  215. if($tags) {
  216. foreach($tags as $tag) { $tag_arr .= $tag->slug . ','; }
  217. $args = array(
  218. 'tag' => $tag_arr,
  219. 'numberposts' => 5, /* you can change this to show more */
  220. 'post__not_in' => array($post->ID)
  221. );
  222. $related_posts = get_posts($args);
  223. if($related_posts) {
  224. foreach ($related_posts as $post) : setup_postdata($post); ?>
  225. <li class="related_post"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  226. <?php endforeach; }
  227. else { ?>
  228. <li class="no_related_post">No Related Posts Yet!</li>
  229. <?php }
  230. }
  231. wp_reset_query();
  232. echo '</ul>';
  233. } /* end bones related posts function */
  234. /*********************
  235. PAGE NAVI
  236. *********************/
  237. // Numeric Page Navi (built into the theme by default)
  238. function bones_page_navi($before = '', $after = '') {
  239. global $wpdb, $wp_query;
  240. $request = $wp_query->request;
  241. $posts_per_page = intval(get_query_var('posts_per_page'));
  242. $paged = intval(get_query_var('paged'));
  243. $numposts = $wp_query->found_posts;
  244. $max_page = $wp_query->max_num_pages;
  245. if ( $numposts <= $posts_per_page ) { return; }
  246. if(empty($paged) || $paged == 0) {
  247. $paged = 1;
  248. }
  249. $pages_to_show = 7;
  250. $pages_to_show_minus_1 = $pages_to_show-1;
  251. $half_page_start = floor($pages_to_show_minus_1/2);
  252. $half_page_end = ceil($pages_to_show_minus_1/2);
  253. $start_page = $paged - $half_page_start;
  254. if($start_page <= 0) {
  255. $start_page = 1;
  256. }
  257. $end_page = $paged + $half_page_end;
  258. if(($end_page - $start_page) != $pages_to_show_minus_1) {
  259. $end_page = $start_page + $pages_to_show_minus_1;
  260. }
  261. if($end_page > $max_page) {
  262. $start_page = $max_page - $pages_to_show_minus_1;
  263. $end_page = $max_page;
  264. }
  265. if($start_page <= 0) {
  266. $start_page = 1;
  267. }
  268. echo $before.'<nav class="page-navigation"><ol class="bones_page_navi clearfix">'."";
  269. if ($start_page >= 2 && $pages_to_show < $max_page) {
  270. $first_page_text = "First";
  271. echo '<li class="bpn-first-page-link"><a href="'.get_pagenum_link().'" title="'.$first_page_text.'">'.$first_page_text.'</a></li>';
  272. }
  273. echo '<li class="bpn-prev-link">';
  274. previous_posts_link('<<');
  275. echo '</li>';
  276. for($i = $start_page; $i <= $end_page; $i++) {
  277. if($i == $paged) {
  278. echo '<li class="bpn-current">'.$i.'</li>';
  279. } else {
  280. echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
  281. }
  282. }
  283. echo '<li class="bpn-next-link">';
  284. next_posts_link('>>');
  285. echo '</li>';
  286. if ($end_page < $max_page) {
  287. $last_page_text = "Last";
  288. echo '<li class="bpn-last-page-link"><a href="'.get_pagenum_link($max_page).'" title="'.$last_page_text.'">'.$last_page_text.'</a></li>';
  289. }
  290. echo '</ol></nav>'.$after."";
  291. } /* end page navi */
  292. /*********************
  293. RANDOM CLEANUP ITEMS
  294. *********************/
  295. // remove the p from around imgs (http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/)
  296. function bones_filter_ptags_on_images($content){
  297. return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
  298. }
  299. // This removes the annoying […] to a Read More link
  300. function bones_excerpt_more($more) {
  301. global $post;
  302. // edit here if you like
  303. return '... <a href="'. get_permalink($post->ID) . '" title="Read '.get_the_title($post->ID).'">Read more &raquo;</a>';
  304. }
  305. ?>