Guest User

Functions

a guest
Nov 4th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.54 KB | None | 0 0
  1. <?php
  2. /*
  3. Author: Eddie Machado
  4. URL: htp://themble.com/bones/
  5.  
  6. This is where you can drop your custom functions or
  7. just edit things like thumbnail sizes, header images,
  8. sidebars, comments, ect.
  9. */
  10.  
  11. /************* INCLUDE NEEDED FILES ***************/
  12.  
  13. /*
  14. 1. library/bones.php
  15.     - head cleanup (remove rsd, uri links, junk css, ect)
  16.     - enqueueing scripts & styles
  17.     - theme support functions
  18.     - custom menu output & fallbacks
  19.     - related post function
  20.     - page-navi function
  21.     - removing <p> from around images
  22.     - customizing the post excerpt
  23.     - custom google+ integration
  24.     - adding custom fields to user profiles
  25. */
  26. require_once('library/bones.php'); // if you remove this, bones will break
  27. /*
  28. 2. library/custom-post-type.php
  29.     - an example custom post type
  30.     - example custom taxonomy (like categories)
  31.     - example custom taxonomy (like tags)
  32. */
  33. require_once('library/metaboxes/category-metabox-functions.php');
  34. require_once('library/metaboxes/metabox-functions.php');
  35. /*
  36. 3. library/admin.php
  37.     - removing some default WordPress dashboard widgets
  38.     - an example custom dashboard widget
  39.     - adding custom login css
  40.     - changing text in footer of admin
  41. */
  42. require_once('library/admin.php'); // this comes turned off by default
  43. /*
  44. 4. library/translation/translation.php
  45.     - adding support for other languages
  46. */
  47. // require_once('library/translation/translation.php'); // this comes turned off by default
  48.  
  49. /************* THUMBNAIL SIZE OPTIONS *************/
  50.  
  51. // Thumbnail sizes
  52. add_image_size( 'single-post-image', 270, 270, true );
  53. add_image_size( 'prod-cat-image', 980, 155, true );
  54. /*
  55. to add more sizes, simply copy a line from above
  56. and change the dimensions & name. As long as you
  57. upload a "featured image" as large as the biggest
  58. set width or height, all the other sizes will be
  59. auto-cropped.
  60.  
  61. To call a different size, simply change the text
  62. inside the thumbnail function.
  63.  
  64. For example, to call the 300 x 300 sized image,
  65. we would use the function:
  66. <?php the_post_thumbnail( 'bones-thumb-300' ); ?>
  67. for the 600 x 100 image:
  68. <?php the_post_thumbnail( 'bones-thumb-600' ); ?>
  69.  
  70. You can change the names and dimensions to whatever
  71. you like. Enjoy!
  72. */
  73.  
  74. /************* ACTIVE SIDEBARS ********************/
  75.  
  76. // Sidebars & Widgetizes Areas
  77. function bones_register_sidebars() {
  78.     register_sidebar(array(
  79.         'id' => 'sidebar1',
  80.         'name' => __('Sidebar 1', 'bonestheme'),
  81.         'description' => __('The homepage sidebar (below buy online dropdowns).', 'bonestheme'),
  82.         'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-top">&nbsp;</div><div class="widget-body">',
  83.         'after_widget' => '</div><div class="widget-bottom">&nbsp;</div></div>',
  84.         'before_title' => '<h4 class="widgettitle">',
  85.         'after_title' => '</h4>',
  86.     ));
  87.    
  88.      register_sidebar(array(
  89.         'id' => 'sidebar2',
  90.         'name' => __('Sidebar 2', 'bonestheme'),
  91.         'description' => __('The general sidebar (appears top on all pages except homepage).', 'bonestheme'),
  92.         'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-top">&nbsp;</div><div class="widget-body">',
  93.         'after_widget' => '</div><div class="widget-bottom">&nbsp;</div></div>',
  94.         'before_title' => '<h4 class="widgettitle">',
  95.         'after_title' => '</h4>',
  96.     ));
  97.    
  98.      register_sidebar(array(
  99.         'id' => 'sidebar3',
  100.         'name' => __('Sidebar 3', 'bonestheme'),
  101.         'description' => __('The sidebar that appears at the top on the homepage.', 'bonestheme'),
  102.         'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-top">&nbsp;</div><div class="widget-body">',
  103.         'after_widget' => '</div><div class="widget-bottom">&nbsp;</div></div>',
  104.         'before_title' => '<h4 class="widgettitle">',
  105.         'after_title' => '</h4>',
  106.     ));
  107.    
  108.          register_sidebar(array(
  109.         'id' => 'sidebar4',
  110.         'name' => __('Sidebar 4', 'bonestheme'),
  111.         'description' => __('The sidebar that appears below other widgets on general pages.', 'bonestheme'),
  112.         'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-top">&nbsp;</div><div class="widget-body">',
  113.         'after_widget' => '</div><div class="widget-bottom">&nbsp;</div></div>',
  114.         'before_title' => '<h4 class="widgettitle">',
  115.         'after_title' => '</h4>',
  116.     ));
  117.    
  118.     /*
  119.     to add more sidebars or widgetized areas, just copy
  120.     and edit the above sidebar code. In order to call
  121.     your new sidebar just use the following code:
  122.    
  123.     Just change the name to whatever your new
  124.     sidebar's id is, for example:
  125.    
  126.     register_sidebar(array(
  127.         'id' => 'sidebar2',
  128.         'name' => __('Sidebar 2', 'bonestheme'),
  129.         'description' => __('The second (secondary) sidebar.', 'bonestheme'),
  130.         'before_widget' => '<div id="%1$s" class="widget %2$s">',
  131.         'after_widget' => '</div>',
  132.         'before_title' => '<h4 class="widgettitle">',
  133.         'after_title' => '</h4>',
  134.     ));
  135.    
  136.     To call the sidebar in your template, you can just copy
  137.     the sidebar.php file and rename it to your sidebar's name.
  138.     So using the above example, it would be:
  139.     sidebar-sidebar2.php
  140.    
  141.     */
  142. } // don't remove this bracket!
  143.  
  144. /************* COMMENT LAYOUT *********************/
  145.        
  146. // Comment Layout
  147. function bones_comments($comment, $args, $depth) {
  148.    $GLOBALS['comment'] = $comment; ?>
  149.     <li <?php comment_class(); ?>>
  150.         <article id="comment-<?php comment_ID(); ?>" class="clearfix">
  151.             <header class="comment-author vcard">
  152.                 <?php
  153.                 /*
  154.                     this is the new responsive optimized comment image. It used the new HTML5 data-attribute to display comment gravatars on larger screens only. What this means is that on larger posts, mobile sites don't have a ton of requests for comment images. This makes load time incredibly fast! If you'd like to change it back, just replace it with the regular wordpress gravatar call:
  155.                     echo get_avatar($comment,$size='32',$default='<path_to_url>' );
  156.                 */
  157.                 ?>
  158.                 <!-- custom gravatar call -->
  159.                 <?php
  160.                     // create variable
  161.                     $bgauthemail = get_comment_author_email();
  162.                 ?>
  163.                 <img data-gravatar="http://www.gravatar.com/avatar/<?php echo md5($bgauthemail); ?>?s=32" class="load-gravatar avatar avatar-48 photo" height="32" width="32" src="<?php echo get_template_directory_uri(); ?>/library/images/nothing.gif" />
  164.                 <!-- end custom gravatar call -->
  165.                 <?php printf(__('<cite class="fn">%s</cite>', 'bonestheme'), get_comment_author_link()) ?>
  166.                 <time datetime="<?php echo comment_time('Y-m-j'); ?>"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php comment_time(__('F jS, Y', 'bonestheme')); ?> </a></time>
  167.                 <?php edit_comment_link(__('(Edit)', 'bonestheme'),'  ','') ?>
  168.             </header>
  169.             <?php if ($comment->comment_approved == '0') : ?>
  170.                 <div class="alert info">
  171.                     <p><?php _e('Your comment is awaiting moderation.', 'bonestheme') ?></p>
  172.                 </div>
  173.             <?php endif; ?>
  174.             <section class="comment_content clearfix">
  175.                 <?php comment_text() ?>
  176.             </section>
  177.             <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  178.         </article>
  179.     <!-- </li> is added by WordPress automatically -->
  180. <?php
  181. } // don't remove this bracket!
  182.  
  183. /************* SEARCH FORM LAYOUT *****************/
  184.  
  185. // Search Form
  186. function bones_wpsearch($form) {
  187.     $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
  188.    <label class="screen-reader-text" for="s">' . __('Search for:', 'bonestheme') . '</label>
  189.    <input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="'.esc_attr__('Search the Site...','bonestheme').'" />
  190.    <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
  191.    </form>';
  192.     return $form;
  193. } // don't remove this bracket!
  194.  
  195. //Lists Children of $postp if there are any.
  196. function childposts($postp){
  197. $children = wp_list_pages("title_li=&child_of=".$postp."&echo=0");
  198. if ($children) { ?>
  199. <ul>
  200. <?php echo $children; ?>
  201. </ul>
  202. <?php }} ?>
  203. <?php
  204. function site_information_widget(){
  205.     echo "<p>". bloginfo('description') ."</p><hr />";
  206.      $num_page = wp_count_posts( 'page' );
  207.      $pagenum = number_format_i18n( $num_page->publish );
  208.      $num_posts = wp_count_posts( 'post' );
  209.      $postnum = number_format_i18n( $num_posts->publish );
  210.      echo "<p>This site has <a href='edit.php?post_type=page'>".$pagenum." Pages</a> and <a href='edit.php?post_type=post'>".$postnum." Posts</a>.</p>";
  211.   $post_types = get_post_types( array( '_builtin' => false ), 'objects' );
  212.     foreach ( $post_types as $post_type ) {
  213.         if($post_type->name !== 'wp-types-group' && $post_type->name !== 'wpcf7_contact_form'){
  214.         $num_posts = wp_count_posts( $post_type->name );
  215.         $num = number_format_i18n( $num_posts->publish );
  216.         $text = _n( $post_type->labels->singular_name, $post_type->labels->name, $num_posts->publish );
  217.         if ( current_user_can( 'edit_posts' ) ) {
  218.             $num = '<p>There are <a href="edit.php?post_type=' . $post_type->name . '">' . $num . '</a> ';
  219.             $text = '<a href="edit.php?post_type=' . $post_type->name . '">' . $text . '</a> on the site';
  220.         }
  221.         echo '<td class="first b b-' . $post_type->name . 's">' . $num . '</td>';
  222.         echo '<td class="t ' . $post_type->name . 's">' . $text . '</td>';
  223.         echo '</tr>';
  224.  
  225.         if ( $num_posts->pending > 0 ) {
  226.             $num = number_format_i18n( $num_posts->pending );
  227.             $text = _n( $post_type->labels->singular_name . ' pending', $post_type->labels->name . ' pending', $num_posts->pending );
  228.             if ( current_user_can( 'edit_posts' ) ) {
  229.                 $num = ', <a href="edit.php?post_status=pending&post_type=' . $post_type->name . '">' . $num . '</a> ';
  230.                 $text = '<a href="edit.php?post_status=pending&post_type=' . $post_type->name . '">' . $text . '</a> review.</p>';
  231.             }
  232.             echo '<td class="first b b-' . $post_type->name . 's">' . $num . '</td>';
  233.             echo '<td class="t ' . $post_type->name . 's">' . $text . '</td>';
  234.             echo '</tr>';
  235.         } else { echo ".</p>"; }
  236.     }}
  237.     }
  238.  
  239. //truncate title
  240. function customTitle($limit) {
  241.     $title = get_the_title($post->ID);
  242.     if(strlen($title) > $limit) {
  243.         $title = substr($title, 0, $limit) . '...';
  244.     }
  245.    
  246.     echo $title;
  247. }
  248. // Jigoshop
  249. function mytheme_open_jigoshop_content_wrappers()
  250. {
  251.     echo '<div id="page-banner">
  252.        <div id="page-banner-border" class="wrap clearfix">
  253.         <div class="wrap clearfix">';
  254.          
  255.          include('library/banner.php');
  256.          
  257.          echo '</div>';
  258.    
  259.     echo '<div id="content">
  260.  
  261.                 <div id="inner-content" class="wrap clearfix">
  262.            
  263.                     <div id="main" class="ninecol first clearfix" role="main">';
  264. }
  265.  
  266. function mytheme_close_jigoshop_content_wrappers()
  267. {
  268.     echo '</div>';
  269. }
  270.  
  271. function mytheme_prepare_jigoshop_wrappers()
  272. {
  273.     remove_action( 'jigoshop_before_main_content', 'jigoshop_output_content_wrapper', 10 );
  274.     remove_action( 'jigoshop_after_main_content', 'jigoshop_output_content_wrapper_end', 10);
  275.  
  276.     add_action( 'jigoshop_before_main_content', 'mytheme_open_jigoshop_content_wrappers', 10 );
  277.     add_action( 'jigoshop_after_main_content', 'mytheme_close_jigoshop_content_wrappers', 10 );
  278. }
  279. add_action( 'wp_head', 'mytheme_prepare_jigoshop_wrappers' );
  280.  
  281.     function schoolwear_product_dropdown_categories( $show_counts = false, $hierarchal = false ) {
  282.             global $wp_query;
  283.  
  284.             $r = array();
  285.             $r['pad_counts'] = 1;
  286.             $r['hierarchal'] = $hierarchal;
  287.             $r['hide_empty'] = 1;
  288.             $r['show_count'] = 0;
  289.             $r['selected']   = isset( $wp_query->query['product_cat'] ) ? $wp_query->query['product_cat'] : '';
  290.  
  291.             $r['menu_order'] = false; // This is to enable the following order args
  292.             $r['orderby'] = 'id';
  293.             $r['order'] = 'ASC';
  294.             $r['parent'] = 25;
  295.  
  296.             $terms = get_terms( 'product_cat', $r );
  297.  
  298.             if ( ! $terms ) return;
  299.  
  300.             $output  = "<select name='product_cat' id='school_cat'>";
  301.  
  302.             $output .= '<option value="" ' .  selected( isset( $_GET['product_cat'] ) ? esc_attr( $_GET['product_cat'] ) : '', '', false ) . '>'.__('Select...', 'jigoshop').'</option>';
  303.             $output .= jigoshop_walk_category_dropdown_tree( $terms, 0, $r );
  304.             $output .="</select>";
  305.  
  306.             echo $output;
  307.     }
  308.  
  309.    function ranges_categories( $show_counts = false, $hierarchal = false ) {
  310.             global $wp_query;
  311.  
  312.             $r = array();
  313.             $r['pad_counts'] = 1;
  314.             $r['hierarchal'] = $hierarchal;
  315.             $r['hide_empty'] = 0;
  316.             $r['show_count'] = 0;
  317.             $r['selected']   = isset( $wp_query->query['product_cat'] ) ? $wp_query->query['product_cat'] : '';
  318.  
  319.             $r['menu_order'] = false; // This is to enable the following order args
  320.             $r['orderby'] = 'id';
  321.             $r['order'] = 'ASC';
  322.             $r['parent'] = 0;
  323.             $r['exclude'] = 25;
  324.  
  325.             $terms = get_terms( 'product_cat', $r );
  326.  
  327.             if ( ! $terms ) return;
  328.  
  329.             $output  = "<select name='product_cat' id='ranges_cat'>";
  330.  
  331.             $output .= '<option value="" ' .  selected( isset( $_GET['product_cat'] ) ? esc_attr( $_GET['product_cat'] ) : '', '', false ) . '>'.__('Choose a category', 'jigoshop').'</option>';
  332.             $output .= jigoshop_walk_category_dropdown_tree( $terms, 0, $r );
  333.             $output .="</select>";
  334.  
  335.             echo $output;
  336.     }
  337.     //options
  338. // KEYWORDS from content
  339. function get_keywords($text, $letterlimit, $wordlimit)
  340. {
  341.     $string = '';
  342.  
  343. $text=strip_tags($text);  // not neccssary for none HTML
  344. //$text=strip_shortcodes($text); // uncomment only inside wordpress system
  345. $text = trim(preg_replace("/\s+/"," ",$text));
  346. $text=str_replace(",","",$text);
  347. $text=str_replace(".","",$text);
  348. $word_array = explode(" ", $text);
  349. $words =0;
  350.    
  351. foreach ($word_array as $key=>$word)
  352. {
  353.     if ($words < $wordlimit){
  354.     if (strlen($word) > $letterlimit)
  355.     {
  356.     $string[$key] = $word ;
  357.     ++$words;
  358.     }
  359.     }
  360. }
  361.  if ($string != ""){
  362.  $text = implode(", ", $string); }
  363.  else {$text = implode(", ", $word_array);}
  364.  return $text;
  365.   }
  366. // Custom Description
  367. function custom_description($text = '') {
  368.         $text = do_shortcode( $text );
  369.         $text = apply_filters('the_content', $text);
  370.         $text = str_replace(']]>', ']]>', $text);
  371.         $excerpt_length = 42;
  372.         $text = wp_trim_words( $text, $excerpt_length, $more = '...' );
  373.     return $text;
  374. }
  375. ?>
Advertisement
Add Comment
Please, Sign In to add comment