bones.php 14 KB

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