Advertisement
Guest User

bones.php

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