bones.php 13 KB

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