bones.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. // Adding Translation Option
  11. load_theme_textdomain( 'bonestheme', TEMPLATEPATH.'/languages' );
  12. $locale = get_locale();
  13. $locale_file = TEMPLATEPATH."/languages/$locale.php";
  14. if ( is_readable($locale_file) ) require_once($locale_file);
  15. // Cleaning up the Wordpress Head
  16. function bones_head_cleanup() {
  17. // remove header links
  18. remove_action( 'wp_head', 'feed_links_extra', 3 ); // Category Feeds
  19. remove_action( 'wp_head', 'feed_links', 2 ); // Post and Comment Feeds
  20. remove_action( 'wp_head', 'rsd_link' ); // EditURI link
  21. remove_action( 'wp_head', 'wlwmanifest_link' ); // Windows Live Writer
  22. remove_action( 'wp_head', 'index_rel_link' ); // index link
  23. remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // previous link
  24. remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
  25. remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Links for Adjacent Posts
  26. remove_action( 'wp_head', 'wp_generator' ); // WP version
  27. if (!is_admin()) {
  28. wp_deregister_script('jquery'); // De-Register jQuery
  29. wp_register_script('jquery', '', '', '', true); // It's already in the Header
  30. }
  31. }
  32. // launching operation cleanup
  33. add_action('init', 'bones_head_cleanup');
  34. // remove WP version from RSS
  35. function bones_rss_version() { return ''; }
  36. add_filter('the_generator', 'bones_rss_version');
  37. // loading jquery reply elements on single pages automatically
  38. function bones_queue_js(){ if (!is_admin()){ if ( is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) wp_enqueue_script( 'comment-reply' ); }
  39. }
  40. // reply on comments script
  41. add_action('wp_print_scripts', 'bones_queue_js');
  42. // Fixing the Read More in the Excerpts
  43. // This removes the annoying […] to a Read More link
  44. function bones_excerpt_more($more) {
  45. global $post;
  46. // edit here if you like
  47. return '... <a href="'. get_permalink($post->ID) . '" title="Read '.get_the_title($post->ID).'">Read more &raquo;</a>';
  48. }
  49. add_filter('excerpt_more', 'bones_excerpt_more');
  50. // Adding WP 3+ Functions & Theme Support
  51. function bones_theme_support() {
  52. add_theme_support('post-thumbnails'); // wp thumbnails (sizes handled in functions.php)
  53. set_post_thumbnail_size(125, 125, true); // default thumb size
  54. add_custom_background(); // wp custom background
  55. add_theme_support('automatic-feed-links'); // rss thingy
  56. // to add header image support go here: http://themble.com/support/adding-header-background-image-support/
  57. // adding post format support
  58. add_theme_support( 'post-formats', // post formats
  59. array(
  60. 'aside', // title less blurb
  61. 'gallery', // gallery of images
  62. 'link', // quick link to other site
  63. 'image', // an image
  64. 'quote', // a quick quote
  65. 'status', // a Facebook like status update
  66. 'video', // video
  67. 'audio', // audio
  68. 'chat' // chat transcript
  69. )
  70. );
  71. add_theme_support( 'menus' ); // wp menus
  72. register_nav_menus( // wp3+ menus
  73. array(
  74. 'main_nav' => 'The Main Menu', // main nav in header
  75. 'footer_links' => 'Footer Links' // secondary nav in footer
  76. )
  77. );
  78. }
  79. // launching this stuff after theme setup
  80. add_action('after_setup_theme','bones_theme_support');
  81. // adding sidebars to Wordpress (these are created in functions.php)
  82. add_action( 'widgets_init', 'bones_register_sidebars' );
  83. // adding the bones search form (created in functions.php)
  84. add_filter( 'get_search_form', 'bones_wpsearch' );
  85. function bones_main_nav() {
  86. // display the wp3 menu if available
  87. wp_nav_menu(
  88. array(
  89. 'menu' => 'main_nav', /* menu name */
  90. 'theme_location' => 'main_nav', /* where in the theme it's assigned */
  91. 'container_class' => 'menu clearfix', /* container class */
  92. 'fallback_cb' => 'bones_main_nav_fallback' /* menu fallback */
  93. )
  94. );
  95. }
  96. function bones_footer_links() {
  97. // display the wp3 menu if available
  98. wp_nav_menu(
  99. array(
  100. 'menu' => 'footer_links', /* menu name */
  101. 'theme_location' => 'footer_links', /* where in the theme it's assigned */
  102. 'container_class' => 'footer-links clearfix', /* container class */
  103. 'fallback_cb' => 'bones_footer_links_fallback' /* menu fallback */
  104. )
  105. );
  106. }
  107. // this is the fallback for header menu
  108. function bones_main_nav_fallback() {
  109. wp_page_menu( 'show_home=Home&menu_class=menu' );
  110. }
  111. // this is the fallback for footer menu
  112. function bones_footer_links_fallback() {
  113. /* you can put a default here if you like */
  114. }
  115. /****************** PLUGINS & EXTRA FEATURES **************************/
  116. // Related Posts Function (call using bones_related_posts(); )
  117. function bones_related_posts() {
  118. echo '<ul id="bones-related-posts">';
  119. global $post;
  120. $tags = wp_get_post_tags($post->ID);
  121. if($tags) {
  122. foreach($tags as $tag) { $tag_arr .= $tag->slug . ','; }
  123. $args = array(
  124. 'tag' => $tag_arr,
  125. 'numberposts' => 5, /* you can change this to show more */
  126. 'post__not_in' => array($post->ID)
  127. );
  128. $related_posts = get_posts($args);
  129. if($related_posts) {
  130. foreach ($related_posts as $post) : setup_postdata($post); ?>
  131. <li class="related_post"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  132. <?php endforeach; }
  133. else { ?>
  134. <li class="no_related_post">No Related Posts Yet!</li>
  135. <?php }
  136. }
  137. wp_reset_query();
  138. echo '</ul>';
  139. }
  140. // Numeric Page Navi (built into the theme by default)
  141. function page_navi($before = '', $after = '') {
  142. global $wpdb, $wp_query;
  143. $request = $wp_query->request;
  144. $posts_per_page = intval(get_query_var('posts_per_page'));
  145. $paged = intval(get_query_var('paged'));
  146. $numposts = $wp_query->found_posts;
  147. $max_page = $wp_query->max_num_pages;
  148. if ( $numposts <= $posts_per_page ) { return; }
  149. if(empty($paged) || $paged == 0) {
  150. $paged = 1;
  151. }
  152. $pages_to_show = 7;
  153. $pages_to_show_minus_1 = $pages_to_show-1;
  154. $half_page_start = floor($pages_to_show_minus_1/2);
  155. $half_page_end = ceil($pages_to_show_minus_1/2);
  156. $start_page = $paged - $half_page_start;
  157. if($start_page <= 0) {
  158. $start_page = 1;
  159. }
  160. $end_page = $paged + $half_page_end;
  161. if(($end_page - $start_page) != $pages_to_show_minus_1) {
  162. $end_page = $start_page + $pages_to_show_minus_1;
  163. }
  164. if($end_page > $max_page) {
  165. $start_page = $max_page - $pages_to_show_minus_1;
  166. $end_page = $max_page;
  167. }
  168. if($start_page <= 0) {
  169. $start_page = 1;
  170. }
  171. echo $before.'<nav class="page-navigation"><ol class="bones_page_navi clearfix">'."";
  172. if ($start_page >= 2 && $pages_to_show < $max_page) {
  173. $first_page_text = "First";
  174. echo '<li class="bpn-first-page-link"><a href="'.get_pagenum_link().'" title="'.$first_page_text.'">'.$first_page_text.'</a></li>';
  175. }
  176. echo '<li class="bpn-prev-link">';
  177. previous_posts_link('<<');
  178. echo '</li>';
  179. for($i = $start_page; $i <= $end_page; $i++) {
  180. if($i == $paged) {
  181. echo '<li class="bpn-current">'.$i.'</li>';
  182. } else {
  183. echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
  184. }
  185. }
  186. echo '<li class="bpn-next-link">';
  187. next_posts_link('>>');
  188. echo '</li>';
  189. if ($end_page < $max_page) {
  190. $last_page_text = "Last";
  191. echo '<li class="bpn-last-page-link"><a href="'.get_pagenum_link($max_page).'" title="'.$last_page_text.'">'.$last_page_text.'</a></li>';
  192. }
  193. echo '</ol></nav>'.$after."";
  194. }
  195. ?>