Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Add Translation Option
- load_theme_textdomain( 'wpbootstrap', TEMPLATEPATH.'/languages' );
- $locale = get_locale();
- $locale_file = TEMPLATEPATH . "/languages/$locale.php";
- if ( is_readable( $locale_file ) ) require_once( $locale_file );
- // Clean up the WordPress Head
- if( !function_exists( "wp_bootstrap_head_cleanup" ) ) {
- function wp_bootstrap_head_cleanup() {
- // remove header links
- remove_action( 'wp_head', 'feed_links_extra', 3 ); // Category Feeds
- remove_action( 'wp_head', 'feed_links', 2 ); // Post and Comment Feeds
- remove_action( 'wp_head', 'rsd_link' ); // EditURI link
- remove_action( 'wp_head', 'wlwmanifest_link' ); // Windows Live Writer
- remove_action( 'wp_head', 'index_rel_link' ); // index link
- remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // previous link
- remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
- remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Links for Adjacent Posts
- remove_action( 'wp_head', 'wp_generator' ); // WP version
- }
- }
- // Launch operation cleanup
- add_action( 'init', 'wp_bootstrap_head_cleanup' );
- // remove WP version from RSS
- if( !function_exists( "wp_bootstrap_rss_version" ) ) {
- function wp_bootstrap_rss_version() { return ''; }
- }
- add_filter( 'the_generator', 'wp_bootstrap_rss_version' );
- // Remove the […] in a Read More link
- if( !function_exists( "wp_bootstrap_excerpt_more" ) ) {
- function wp_bootstrap_excerpt_more( $more ) {
- global $post;
- return '<span class="after-desc">›</span>';
- }
- }
- add_filter('excerpt_more', 'wp_bootstrap_excerpt_more');
- // Add WP 3+ Functions & Theme Support
- if( !function_exists( "wp_bootstrap_theme_support" ) ) {
- function wp_bootstrap_theme_support() {
- add_theme_support( 'post-thumbnails' ); // wp thumbnails (sizes handled in functions.php)
- set_post_thumbnail_size( 125, 125, true ); // default thumb size
- add_theme_support( 'custom-background' ); // wp custom background
- add_theme_support( 'automatic-feed-links' ); // rss
- // Add post format support - if these are not needed, comment them out
- add_theme_support( 'post-formats', // post formats
- array(
- 'aside', // title less blurb
- 'gallery', // gallery of images
- 'link', // quick link to other site
- 'image', // an image
- 'quote', // a quick quote
- 'status', // a Facebook like status update
- 'video', // video
- 'audio', // audio
- 'chat' // chat transcript
- )
- );
- add_theme_support( 'menus' ); // wp menus
- register_nav_menus( // wp3+ menus
- array(
- 'main_nav' => 'The Main Menu', // main nav in header
- 'footer_links' => 'Footer Links' // secondary nav in footer
- )
- );
- }
- }
- // launching this stuff after theme setup
- add_action( 'after_setup_theme','wp_bootstrap_theme_support' );
- function wp_bootstrap_main_nav() {
- // Display the WordPress menu if available
- wp_nav_menu(
- array(
- 'menu' => 'main_nav', /* menu name */
- 'menu_class' => 'nav navbar-nav',
- 'theme_location' => 'main_nav', /* where in the theme it's assigned */
- 'container' => 'false', /* container class */
- 'fallback_cb' => 'wp_bootstrap_main_nav_fallback', /* menu fallback */
- 'walker' => new Bootstrap_walker()
- )
- );
- }
- function wp_bootstrap_footer_links() {
- // Display the WordPress menu if available
- wp_nav_menu(
- array(
- 'menu' => 'footer_links', /* menu name */
- 'theme_location' => 'footer_links', /* where in the theme it's assigned */
- 'container_class' => 'footer-links', /* container class */
- 'fallback_cb' => 'wp_bootstrap_footer_links_fallback' /* menu fallback */
- )
- );
- }
- // this is the fallback for header menu
- function wp_bootstrap_main_nav_fallback() {
- /* you can put a default here if you like */
- }
- // this is the fallback for footer menu
- function wp_bootstrap_footer_links_fallback() {
- /* you can put a default here if you like */
- }
- // Shortcodes
- require_once('library/shortcodes.php');
- // Admin Functions (commented out by default)
- // require_once('library/admin.php'); // custom admin functions
- // Custom Backend Footer
- add_filter('admin_footer_text', 'wp_bootstrap_custom_admin_footer');
- function wp_bootstrap_custom_admin_footer() {
- echo '<span id="footer-thankyou">Developed by <a href="http://320press.com" target="_blank">320press</a></span>. Built using <a href="http://themble.com/bones" target="_blank">Bones</a>.';
- }
- // adding it to the admin area
- add_filter('admin_footer_text', 'wp_bootstrap_custom_admin_footer');
- // Set content width
- if ( ! isset( $content_width ) ) $content_width = 580;
- /************* THUMBNAIL SIZE OPTIONS *************/
- // Thumbnail sizes
- add_image_size( 'wpbs-featured', 780, 300, true );
- add_image_size( 'wpbs-featured-home', 970, 311, true);
- add_image_size( 'wpbs-featured-carousel', 970, 400, true);
- /*
- to add more sizes, simply copy a line from above
- and change the dimensions & name. As long as you
- upload a "featured image" as large as the biggest
- set width or height, all the other sizes will be
- auto-cropped.
- To call a different size, simply change the text
- inside the thumbnail function.
- For example, to call the 300 x 300 sized image,
- we would use the function:
- <?php the_post_thumbnail( 'bones-thumb-300' ); ?>
- for the 600 x 100 image:
- <?php the_post_thumbnail( 'bones-thumb-600' ); ?>
- You can change the names and dimensions to whatever
- you like. Enjoy!
- */
- /************* ACTIVE SIDEBARS ********************/
- // Sidebars & Widgetizes Areas
- function wp_bootstrap_register_sidebars() {
- register_sidebar(array(
- 'id' => 'sidebar1',
- 'name' => 'Main Sidebar',
- 'description' => 'Used on every page BUT the homepage page template.',
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h4 class="widgettitle">',
- 'after_title' => '</h4>',
- ));
- register_sidebar(array(
- 'id' => 'sidebar2',
- 'name' => 'Homepage Sidebar',
- 'description' => 'Used only on the homepage page template.',
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h4 class="widgettitle">',
- 'after_title' => '</h4>',
- ));
- register_sidebar(array(
- 'id' => 'footer1',
- 'name' => 'Footer 1',
- 'before_widget' => '<div id="%1$s" class="widget col-sm-3 %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h4 class="widgettitle">',
- 'after_title' => '</h4>',
- ));
- register_sidebar(array(
- 'id' => 'footer2',
- 'name' => 'Footer 2',
- 'before_widget' => '<div id="%1$s" class="widget col-sm-3 %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h4 class="widgettitle">',
- 'after_title' => '</h4>',
- ));
- register_sidebar(array(
- 'id' => 'footer3',
- 'name' => 'Footer 3',
- 'before_widget' => '<div id="%1$s" class="widget col-sm-4 %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h4 class="widgettitle">',
- 'after_title' => '</h4>',
- ));
- /*
- to add more sidebars or widgetized areas, just copy
- and edit the above sidebar code. In order to call
- your new sidebar just use the following code:
- Just change the name to whatever your new
- sidebar's id is, for example:
- To call the sidebar in your template, you can just copy
- the sidebar.php file and rename it to your sidebar's name.
- So using the above example, it would be:
- sidebar-sidebar2.php
- */
- } // don't remove this bracket!
- add_action( 'widgets_init', 'wp_bootstrap_register_sidebars' );
- /************* COMMENT LAYOUT *********************/
- // Comment Layout
- function wp_bootstrap_comments($comment, $args, $depth) {
- $GLOBALS['comment'] = $comment; ?>
- <li <?php comment_class(); ?>
- <article id="comment-<?php comment_ID(); ?>" class="clearfix">
- <div class="comment-author vcard clearfix">
- <div class="avatar col-sm-3">
- <?php echo get_avatar( $comment, $size='75' ); ?>
- </div>
- <div class="col-sm-9 comment-text">
- <?php printf('<h4>%s</h4>', get_comment_author_link()) ?>
- <?php edit_comment_link(__('Edit','wpbootstrap'),'<span class="edit-comment btn btn-sm btn-info"><i class="glyphicon-white glyphicon-pencil"></i>','</span>') ?>
- <?php if ($comment->comment_approved == '0') : ?>
- <div class="alert-message success">
- <p><?php _e('Your comment is awaiting moderation.','wpbootstrap') ?></p>
- </div>
- <?php endif; ?>
- <?php comment_text() ?>
- <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'); ?> </a></time>
- <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
- </div>
- </div>
- </article>
- <!-- </li> is added by wordpress automatically -->
- <?php
- } // don't remove this bracket!
- // Display trackbacks/pings callback function
- function list_pings($comment, $args, $depth) {
- $GLOBALS['comment'] = $comment;
- ?>
- <li id="comment-<?php comment_ID(); ?>"><i class="icon icon-share-alt"></i> <?php comment_author_link(); ?>
- <?php
- }
- /************* SEARCH FORM LAYOUT *****************/
- /****************** password protected post form *****/
- add_filter( 'the_password_form', 'wp_bootstrap_custom_password_form' );
- function wp_bootstrap_custom_password_form() {
- global $post;
- $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
- $o = '<div class="clearfix"><form class="protected-post-form" action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
- ' . '<p>' . __( "This post is password protected. To view it please enter your password below:" ,'wpbootstrap') . '</p>' . '
- <label for="' . $label . '">' . __( "Password:" ,'wpbootstrap') . ' </label><div class="input-append"><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" class="btn btn-primary" value="' . esc_attr__( "Submit",'wpbootstrap' ) . '" /></div>
- </form></div>
- ';
- return $o;
- }
- /*********** update standard wp tag cloud widget so it looks better ************/
- add_filter( 'widget_tag_cloud_args', 'wp_bootstrap_my_widget_tag_cloud_args' );
- function wp_bootstrap_my_widget_tag_cloud_args( $args ) {
- $args['number'] = 20; // show less tags
- $args['largest'] = 9.75; // make largest and smallest the same - i don't like the varying font-size look
- $args['smallest'] = 9.75;
- $args['unit'] = 'px';
- return $args;
- }
- // filter tag clould output so that it can be styled by CSS
- function wp_bootstrap_add_tag_class( $taglinks ) {
- $tags = explode('</a>', $taglinks);
- $regex = "#(.*tag-link[-])(.*)(' title.*)#e";
- foreach( $tags as $tag ) {
- $tagn[] = preg_replace($regex, "('$1$2 label tag-'.get_tag($2)->slug.'$3')", $tag );
- }
- $taglinks = implode('</a>', $tagn);
- return $taglinks;
- }
- add_action( 'wp_tag_cloud', 'wp_bootstrap_add_tag_class' );
- add_filter( 'wp_tag_cloud','wp_bootstrap_wp_tag_cloud_filter', 10, 2) ;
- function wp_bootstrap_wp_tag_cloud_filter( $return, $args )
- {
- return '<div id="tag-cloud">' . $return . '</div>';
- }
- // Enable shortcodes in widgets
- add_filter( 'widget_text', 'do_shortcode' );
- // Disable jump in 'read more' link
- function wp_bootstrap_remove_more_jump_link( $link ) {
- $offset = strpos($link, '#more-');
- if ( $offset ) {
- $end = strpos( $link, '"',$offset );
- }
- if ( $end ) {
- $link = substr_replace( $link, '', $offset, $end-$offset );
- }
- return $link;
- }
- add_filter( 'the_content_more_link', 'wp_bootstrap_remove_more_jump_link' );
- // Remove height/width attributes on images so they can be responsive
- add_filter( 'post_thumbnail_html', 'wp_bootstrap_remove_thumbnail_dimensions', 10 );
- add_filter( 'image_send_to_editor', 'wp_bootstrap_remove_thumbnail_dimensions', 10 );
- function wp_bootstrap_remove_thumbnail_dimensions( $html ) {
- $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
- return $html;
- }
- // Add the Meta Box to the homepage template
- function wp_bootstrap_add_homepage_meta_box() {
- global $post;
- // Only add homepage meta box if template being used is the homepage template
- // $post_id = isset($_GET['post']) ? $_GET['post'] : (isset($_POST['post_ID']) ? $_POST['post_ID'] : "");
- $post_id = $post->ID;
- $template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
- if ( $template_file == 'page-homepage.php' ){
- add_meta_box(
- 'homepage_meta_box', // $id
- 'Optional Homepage Tagline', // $title
- 'wp_bootstrap_show_homepage_meta_box', // $callback
- 'page', // $page
- 'normal', // $context
- 'high'); // $priority
- }
- }
- add_action( 'add_meta_boxes', 'wp_bootstrap_add_homepage_meta_box' );
- // Field Array
- $prefix = 'custom_';
- $custom_meta_fields = array(
- array(
- 'label'=> 'Homepage tagline area',
- 'desc' => 'Displayed underneath page title. Only used on homepage template. HTML can be used.',
- 'id' => $prefix.'tagline',
- 'type' => 'textarea'
- )
- );
- // The Homepage Meta Box Callback
- function wp_bootstrap_show_homepage_meta_box() {
- global $custom_meta_fields, $post;
- // Use nonce for verification
- wp_nonce_field( basename( __FILE__ ), 'wpbs_nonce' );
- // Begin the field table and loop
- echo '<table class="form-table">';
- foreach ( $custom_meta_fields as $field ) {
- // get value of this field if it exists for this post
- $meta = get_post_meta($post->ID, $field['id'], true);
- // begin a table row with
- echo '<tr>
- <th><label for="'.$field['id'].'">'.$field['label'].'</label></th>
- <td>';
- switch($field['type']) {
- // text
- case 'text':
- echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="60" />
- <br /><span class="description">'.$field['desc'].'</span>';
- break;
- // textarea
- case 'textarea':
- echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="80" rows="4">'.$meta.'</textarea>
- <br /><span class="description">'.$field['desc'].'</span>';
- break;
- } //end switch
- echo '</td></tr>';
- } // end foreach
- echo '</table>'; // end table
- }
- // Save the Data
- function wp_bootstrap_save_homepage_meta( $post_id ) {
- global $custom_meta_fields;
- // verify nonce
- if ( !isset( $_POST['wpbs_nonce'] ) || !wp_verify_nonce($_POST['wpbs_nonce'], basename(__FILE__)) )
- return $post_id;
- // check autosave
- if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
- return $post_id;
- // check permissions
- if ( 'page' == $_POST['post_type'] ) {
- if ( !current_user_can( 'edit_page', $post_id ) )
- return $post_id;
- } elseif ( !current_user_can( 'edit_post', $post_id ) ) {
- return $post_id;
- }
- // loop through fields and save the data
- foreach ( $custom_meta_fields as $field ) {
- $old = get_post_meta( $post_id, $field['id'], true );
- $new = $_POST[$field['id']];
- if ($new && $new != $old) {
- update_post_meta( $post_id, $field['id'], $new );
- } elseif ( '' == $new && $old ) {
- delete_post_meta( $post_id, $field['id'], $old );
- }
- } // end foreach
- }
- add_action( 'save_post', 'wp_bootstrap_save_homepage_meta' );
- // Add thumbnail class to thumbnail links
- function wp_bootstrap_add_class_attachment_link( $html ) {
- $postid = get_the_ID();
- $html = str_replace( '<a','<a class="thumbnail"',$html );
- return $html;
- }
- add_filter( 'wp_get_attachment_link', 'wp_bootstrap_add_class_attachment_link', 10, 1 );
- // Add lead class to first paragraph
- function wp_bootstrap_first_paragraph( $content ){
- global $post;
- // if we're on the homepage, don't add the lead class to the first paragraph of text
- if( is_page_template( 'page-homepage.php' ) )
- return $content;
- else
- return preg_replace('/<p([^>]+)?>/', '<p$1 class="lead">', $content, 1);
- }
- add_filter( 'the_content', 'wp_bootstrap_first_paragraph' );
- // Menu output mods
- class Bootstrap_walker extends Walker_Nav_Menu{
- function start_el(&$output, $object, $depth = 0, $args = Array(), $current_object_id = 0){
- global $wp_query;
- $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
- $class_names = $value = '';
- // If the item has children, add the dropdown class for bootstrap
- if ( $args->has_children ) {
- $class_names = "dropdown ";
- }
- $classes = empty( $object->classes ) ? array() : (array) $object->classes;
- $class_names .= join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $object ) );
- $class_names = ' class="'. esc_attr( $class_names ) . '"';
- $output .= $indent . '<li id="menu-item-'. $object->ID . '"' . $value . $class_names .'>';
- $attributes = ! empty( $object->attr_title ) ? ' title="' . esc_attr( $object->attr_title ) .'"' : '';
- $attributes .= ! empty( $object->target ) ? ' target="' . esc_attr( $object->target ) .'"' : '';
- $attributes .= ! empty( $object->xfn ) ? ' rel="' . esc_attr( $object->xfn ) .'"' : '';
- $attributes .= ! empty( $object->url ) ? ' href="' . esc_attr( $object->url ) .'"' : '';
- // if the item has children add these two attributes to the anchor tag
- if ( $args->has_children ) {
- $attributes .= ' class="dropdown-toggle" data-toggle="dropdown"';
- }
- $item_output = $args->before;
- $item_output .= '<a'. $attributes .'>';
- $item_output .= $args->link_before .apply_filters( 'the_title', $object->title, $object->ID );
- $item_output .= $args->link_after;
- // if the item has children add the caret just before closing the anchor tag
- if ( $args->has_children ) {
- $item_output .= '<b class="caret"></b></a>';
- }
- else {
- $item_output .= '</a>';
- }
- $item_output .= $args->after;
- $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $object, $depth, $args );
- } // end start_el function
- function start_lvl(&$output, $depth = 0, $args = Array()) {
- $indent = str_repeat("\t", $depth);
- $output .= "\n$indent<ul class=\"dropdown-menu\">\n";
- }
- function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ){
- $id_field = $this->db_fields['id'];
- if ( is_object( $args[0] ) ) {
- $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
- }
- return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
- }
- }
- add_editor_style('editor-style.css');
- function wp_bootstrap_add_active_class($classes, $item) {
- if( $item->menu_item_parent == 0 && in_array('current-menu-item', $classes) ) {
- $classes[] = "active";
- }
- return $classes;
- }
- // Add Twitter Bootstrap's standard 'active' class name to the active nav link item
- add_filter('nav_menu_css_class', 'wp_bootstrap_add_active_class', 10, 2 );
- // enqueue styles
- if( !function_exists("wp_bootstrap_theme_styles") ) {
- function wp_bootstrap_theme_styles() {
- // This is the compiled css file from LESS - this means you compile the LESS file locally and put it in the appropriate directory if you want to make any changes to the master bootstrap.css.
- wp_register_style( 'wpbs', get_template_directory_uri() . '/library/css/styles.css', array(), '1.0', 'all' );
- wp_enqueue_style( 'wpbs' );
- // For child themes
- wp_register_style( 'wpbs-style', get_stylesheet_directory_uri() . '/style.css', array(), '1.0', 'all' );
- wp_enqueue_style( 'wpbs-style' );
- }
- }
- add_action( 'wp_enqueue_scripts', 'wp_bootstrap_theme_styles' );
- // enqueue javascript
- if( !function_exists( "wp_bootstrap_theme_js" ) ) {
- function wp_bootstrap_theme_js(){
- if ( !is_admin() ){
- if ( is_singular() AND comments_open() AND ( get_option( 'thread_comments' ) == 1) )
- wp_enqueue_script( 'comment-reply' );
- }
- // This is the full Bootstrap js distribution file. If you only use a few components that require the js files consider loading them individually instead
- wp_register_script( 'bootstrap',
- get_template_directory_uri() . '/bower_components/bootstrap/dist/js/bootstrap.js',
- array('jquery'),
- '1.2' );
- wp_register_script( 'wpbs-js',
- get_template_directory_uri() . '/library/dist/js/scripts.d1e3d952.min.js',
- array('bootstrap'),
- '1.2' );
- wp_register_script( 'modernizr',
- get_template_directory_uri() . '/bower_components/modernizer/modernizr.js',
- array('jquery'),
- '1.2' );
- wp_enqueue_script( 'bootstrap' );
- wp_enqueue_script( 'wpbs-js' );
- wp_enqueue_script( 'modernizr' );
- }
- }
- add_action( 'wp_enqueue_scripts', 'wp_bootstrap_theme_js' );
- // Get <head> <title> to behave like other themes
- function wp_bootstrap_wp_title( $title, $sep ) {
- global $paged, $page;
- if ( is_feed() ) {
- return $title;
- }
- // Add the site name.
- $title .= get_bloginfo( 'name' );
- // Add the site description for the home/front page.
- $site_description = get_bloginfo( 'description', 'display' );
- if ( $site_description && ( is_home() || is_front_page() ) ) {
- $title = "$title $sep $site_description";
- }
- // Add a page number if necessary.
- if ( $paged >= 2 || $page >= 2 ) {
- $title = "$title $sep " . sprintf( __( 'Page %s', 'wpbootstrap' ), max( $paged, $page ) );
- }
- return $title;
- }
- add_filter( 'wp_title', 'wp_bootstrap_wp_title', 10, 2 );
- // Related Posts Function (call using wp_bootstrap_related_posts(); )
- function wp_bootstrap_related_posts() {
- echo '<ul id="bones-related-posts">';
- global $post;
- $tags = wp_get_post_tags($post->ID);
- if($tags) {
- $tag_arr = "";
- foreach($tags as $tag) { $tag_arr .= $tag->slug . ','; }
- $args = array(
- 'tag' => $tag_arr,
- 'numberposts' => 5, /* you can change this to show more */
- 'post__not_in' => array($post->ID)
- );
- $related_posts = get_posts($args);
- if($related_posts) {
- foreach ($related_posts as $post) : setup_postdata($post); ?>
- <li class="related_post"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
- <?php endforeach; }
- else { ?>
- <li class="no_related_post">No Related Posts Yet!</li>
- <?php }
- }
- wp_reset_query();
- echo '</ul>';
- }
- // Numeric Page Navi (built into the theme by default)
- function wp_bootstrap_page_navi($before = '', $after = '') {
- global $wpdb, $wp_query;
- $request = $wp_query->request;
- $posts_per_page = intval(get_query_var('posts_per_page'));
- $paged = intval(get_query_var('paged'));
- $numposts = $wp_query->found_posts;
- $max_page = $wp_query->max_num_pages;
- if ( $numposts <= $posts_per_page ) { return; }
- if(empty($paged) || $paged == 0) {
- $paged = 1;
- }
- $pages_to_show = 7;
- $pages_to_show_minus_1 = $pages_to_show-1;
- $half_page_start = floor($pages_to_show_minus_1/2);
- $half_page_end = ceil($pages_to_show_minus_1/2);
- $start_page = $paged - $half_page_start;
- if($start_page <= 0) {
- $start_page = 1;
- }
- $end_page = $paged + $half_page_end;
- if(($end_page - $start_page) != $pages_to_show_minus_1) {
- $end_page = $start_page + $pages_to_show_minus_1;
- }
- if($end_page > $max_page) {
- $start_page = $max_page - $pages_to_show_minus_1;
- $end_page = $max_page;
- }
- if($start_page <= 0) {
- $start_page = 1;
- }
- echo $before.'<ul class="pagination">'."";
- if ($paged > 1) {
- $first_page_text = "«";
- echo '<li class="prev"><a href="'.get_pagenum_link().'" title="' . __('First','wpbootstrap') . '">'.$first_page_text.'</a></li>';
- }
- $prevposts = get_previous_posts_link( __('← Previous','wpbootstrap') );
- if($prevposts) { echo '<li>' . $prevposts . '</li>'; }
- else { echo '<li class="disabled"><a href="#">' . __('← Previous','wpbootstrap') . '</a></li>'; }
- for($i = $start_page; $i <= $end_page; $i++) {
- if($i == $paged) {
- echo '<li class="active"><a href="#">'.$i.'</a></li>';
- } else {
- echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
- }
- }
- echo '<li class="">';
- next_posts_link( __('Next →','wpbootstrap') );
- echo '</li>';
- if ($end_page < $max_page) {
- $last_page_text = "»";
- echo '<li class="next"><a href="'.get_pagenum_link($max_page).'" title="' . __('Last','wpbootstrap') . '">'.$last_page_text.'</a></li>';
- }
- echo '</ul>'.$after."";
- }
- // Remove <p> tags from around images
- function wp_bootstrap_filter_ptags_on_images( $content ){
- return preg_replace( '/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content );
- }
- add_filter( 'the_content', 'wp_bootstrap_filter_ptags_on_images' );
- //Lab post type
- add_action( 'init', 'create_posttype' );
- function create_posttype() {
- register_post_type( 'Lab',
- array(
- 'labels' => array(
- 'name' => __( 'Lab pages' ),
- 'singular_name' => __( 'Lab page' )
- ),
- 'public' => true,
- 'has_archive' => true,
- 'rewrite' => array('slug' => 'labs',
- 'with_front' => false
- ),
- )
- );
- }
- // //News post type
- // add_action( 'init', 'create_posttype_news' );
- // function create_posttype_news() {
- // register_post_type( 'News',
- // array(
- // 'labels' => array(
- // 'name' => __( 'News' ),
- // 'singular_name' => __( 'News' )
- // ),
- // 'public' => true,
- // 'has_archive' => true,
- // 'rewrite' => array('slug' => 'news',
- // 'with_front' => false
- // ),
- //
- // )
- // );
- // }
- //events post type
- add_action( 'init', 'create_posttype_events' );
- function create_posttype_events() {
- register_post_type( 'Events',
- array(
- 'labels' => array(
- 'name' => __( 'Events' ),
- 'singular_name' => __( 'Event' )
- ),
- 'public' => true,
- 'has_archive' => true,
- 'taxonomies'=> array( 'category' , 'trends' ),
- 'rewrite' => array('slug' => 'events',
- 'with_front' => false
- ),
- //'taxonomies' => array('trends'),
- )
- );
- }
- // //partners post type
- // add_action( 'init', 'create_posttype_partners' );
- // function create_posttype_partners() {
- // register_post_type( 'Partners',
- // array(
- // 'labels' => array(
- // 'name' => __( 'Partners' ),
- // 'singular_name' => __( 'Partner' )
- // ),
- // 'public' => true,
- // 'has_archive' => false,
- // 'rewrite' => array('slug' => 'partners',
- // 'with_front' => false
- // ),
- // )
- // );
- // }
- //stories post type
- add_action( 'init', 'create_posttype_stories' );
- function create_posttype_stories() {
- register_post_type( 'Stories',
- array(
- 'labels' => array(
- 'name' => __( 'Stories' ),
- 'singular_name' => __( 'Story' )
- ),
- 'public' => true,
- 'has_archive' => true,
- 'rewrite' => array('slug' => 'stories',
- 'with_front' => false,
- ),
- 'taxonomies' => array('trends')
- )
- );
- }
- //stories post type
- add_action( 'init', 'create_posttype_other_posts' );
- function create_posttype_other_posts() {
- register_post_type( 'Other Posts',
- array(
- 'labels' => array(
- 'name' => __( 'Other Posts' ),
- 'singular_name' => __( 'Other Post' )
- ),
- 'public' => true,
- 'has_archive' => false,
- 'rewrite' => array('slug' => 'other-posts',
- 'with_front' => false,
- ),
- //'taxonomies' => array('trends')
- )
- );
- }
- // Microservices post type
- add_action( 'init', 'create_posttype_microservices' );
- function create_posttype_microservices() {
- register_post_type( 'Microservices',
- array(
- 'labels' => array(
- 'name' => __( 'Microservices' ),
- 'singular_name' => __( 'Microservice' )
- ),
- 'public' => true,
- 'has_archive' => true,
- 'rewrite' => array('slug' => 'microservices',
- 'with_front' => false,
- ),
- 'taxonomies' => array('trends')
- )
- );
- }
- //custom taxonomy Trends
- //hook into the init action and call create_book_taxonomies when it fires
- add_action( 'init', 'create_trends_hierarchical_taxonomy', 0 );
- //create a custom taxonomy name it topics for your posts
- function create_trends_hierarchical_taxonomy() {
- // Add new taxonomy, make it hierarchical like categories
- //first do the translations part for GUI
- $labels = array(
- 'name' => _x( 'Trends', 'taxonomy general name' ),
- 'singular_name' => _x( 'Trend', 'taxonomy singular name' ),
- 'search_items' => __( 'Search Trends' ),
- 'all_items' => __( 'All Trends' ),
- 'parent_item' => __( 'Parent Trend' ),
- 'parent_item_colon' => __( 'Parent Trend:' ),
- 'edit_item' => __( 'Edit Trend' ),
- 'update_item' => __( 'Update Trend' ),
- 'add_new_item' => __( 'Add New Trend' ),
- 'new_item_name' => __( 'New Trend Name' ),
- 'menu_name' => __( 'Trends' ),
- );
- // Now register the taxonomy
- register_taxonomy('trends',array('post'), array(
- 'hierarchical' => true,
- 'labels' => $labels,
- 'show_ui' => true,
- 'show_admin_column' => true,
- 'query_var' => true,
- 'rewrite' => array( 'slug' => 'trend' ),
- ));
- }
- //custom taxonomy Maturity
- //hook into the init action and call create_book_taxonomies when it fires
- add_action( 'init', 'create_maturities_hierarchical_taxonomy', 0 );
- //create a custom taxonomy name it topics for your posts
- function create_maturities_hierarchical_taxonomy() {
- // Add new taxonomy, make it hierarchical like categories
- //first do the translations part for GUI
- $labels = array(
- 'name' => _x( 'Maturities', 'taxonomy general name' ),
- 'singular_name' => _x( 'Maturity', 'taxonomy singular name' ),
- 'search_items' => __( 'Search Maturities' ),
- 'all_items' => __( 'All Maturities' ),
- 'parent_item' => __( 'Parent Maturity' ),
- 'parent_item_colon' => __( 'Parent Maturity:' ),
- 'edit_item' => __( 'Edit Maturity' ),
- 'update_item' => __( 'Update Maturity' ),
- 'add_new_item' => __( 'Add New Maturity' ),
- 'new_item_name' => __( 'New Maturity Name' ),
- 'menu_name' => __( 'Maturities' ),
- );
- // Now register the taxonomy
- register_taxonomy('maturity',array('post'), array(
- 'hierarchical' => true,
- 'labels' => $labels,
- 'show_ui' => true,
- 'show_admin_column' => true,
- 'query_var' => true,
- 'rewrite' => array( 'slug' => 'maturity' ),
- ));
- }
- // filtering stories, projects, events
- function misha_filter_function() {
- $filter_args = array(
- 'posts_per_page' => 9,
- 'paged' => $_POST['paged'],
- 'post_type' => array('stories', 'post', 'events'),
- 'post_status' => 'publish',
- 'orderby' => 'date',
- 'order' => 'DESC',
- 'tax_query' => array()
- );
- if (isset($_POST['trend-filter'])) {
- $selected_trend = $_POST['trend-filter'];
- }
- else {
- if (!empty($_GET['trend-filter'])) {
- $selected_trend = $_GET['trend-filter'];
- }
- }
- if (!empty($selected_trend)) {
- $filter_args['tax_query']['queries'][] = array(
- 'taxonomy' => 'trends',
- 'field' => 'slug',
- 'terms' => $selected_trend
- );
- $current_url_trend = 'trend-filter=' . $selected_trend . '&';
- }
- if (isset($_POST['maturity-filter'])) {
- $selected_maturity = $_POST['maturity-filter'];
- }
- else {
- if (!empty($_GET['maturity-filter'])) {
- $selected_maturity = $_GET['maturity-filter'];
- }
- }
- if (!empty($selected_maturity)) {
- $filter_args['tax_query']['queries'][] = array(
- 'taxonomy' => 'maturity',
- 'field' => 'slug',
- 'terms' => $selected_maturity
- );
- $current_url_maturity = 'maturity-filter=' . $selected_maturity . '&';
- }
- $current_url = get_permalink(2308) . '?' . $current_url_trend . $current_url_maturity;
- $filter_query = new WP_Query( $filter_args );
- if($filter_query->have_posts()) {
- while($filter_query->have_posts()) : $filter_query->the_post();
- $post_type = get_post_type_object(get_post_type());
- if ($post_type) {
- $post_type_singular = esc_html($post_type->labels->singular_name);
- }
- ?>
- <div class="col-md-4 col-sm-6 featured post-container animate-reveal post-type-<?php echo get_post_type(); ?>">
- <a href="<?php the_permalink(); ?>">
- <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>
- <div class="featured-heading-container">
- <span class="featured-heading"><?php the_title(); ?></span>
- </div>
- <div class="featured-post-image">
- <span class="post-type-tag"><?php echo $post_type_singular; ?></span>
- <?php
- $image_id = get_field('post_header_image');
- $image_size = 'project-thumb';
- $image_array = wp_get_attachment_image_src($image_id, $image_size);
- $image_url = $image_array[0];
- ?>
- <img src="<?php echo $image_url; ?>" alt="">
- <?php
- if ( get_field( 'header_video' ) ):
- echo '<img class="yt-icon" src="<?php echo get_template_directory_uri(); ?>/library/img/yt.svg">';
- else: // field_name returned false
- endif; // end of if field_name logic
- ?>
- </div>
- <div class="featured-description-container">
- <span class="featured-description"><?php // echo get_excerpt(); ?><?php the_field('post_excerpt'); ?></span>
- <div class="trends-container">
- <?php
- if((get_post_type() == 'events') && (get_field('event_date_and_place'))) {
- echo '<span class="date-container trends">';
- the_field('event_date_and_place');
- echo '</span>';
- }
- ?>
- <?php
- $trends = wp_get_post_terms( get_the_ID(), 'trends', array( 'fields' => 'names' ));
- if ($trends){
- foreach ($trends as $trend) {
- echo '<span class="trends">' . $trend . '</span>';
- }
- }
- ?>
- </div>
- </div>
- <span class="after-desc">›</span>
- </div>
- </article>
- </a>
- </div>
- <?
- endwhile;
- if(($_POST['paged'] == 0) && ($filter_query->max_num_pages > 1)) {
- echo '<div class="malinky-load-more custom-load-more-wrapper"><a href="#" onclick="showMoreFilteredPosts(' . $filter_query->max_num_pages . ');return false;" id="malinky-ajax-pagination-button" class="custom-load-more malinky-load-more__button btn-4a icon-arrow-load-more btn btn-4-bg-none">Load more</a></div>';
- }
- wp_reset_postdata();
- }
- else {
- // no posts found
- }
- wp_die();
- }
- add_action('wp_ajax_myfilter', 'misha_filter_function');
- add_action('wp_ajax_nopriv_myfilter', 'misha_filter_function');
- //next post link class
- add_filter('next_posts_link_attributes', 'posts_link_attributes');
- function posts_link_attributes() {
- return 'class="next-posts"';
- }
- function wt_get_category_count($input = '') {
- global $wpdb;
- if($input == '')
- {
- $category = get_the_category();
- return $category[0]->category_count;
- }
- elseif(is_numeric($input))
- {
- $SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";
- return $wpdb->get_var($SQL);
- }
- else
- {
- $SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug='$input'";
- return $wpdb->get_var($SQL);
- }
- }
- function get_excerpt(){
- $excerpt = get_the_content();
- $excerpt = preg_replace(" ([.*?])",'',$excerpt);
- $excerpt = strip_shortcodes($excerpt);
- $excerpt = strip_tags($excerpt);
- $excerpt = substr($excerpt, 0, 230);
- $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
- $excerpt = trim(preg_replace( '/s+/', ' ', $excerpt));
- $excerpt = $excerpt.'<span class="after-desc">›</span>';
- return $excerpt;
- }
- function load_custom_wp_admin_style() {
- wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/library/css/admin-style.css', false, '1.0.0' );
- wp_enqueue_style( 'custom_wp_admin_css' );
- }
- add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
- function load_custom_wp_admin_script() {
- wp_register_script( 'custom_wp_admin_script', get_template_directory_uri() . '/library/js/admin-script.js', false, '1.0.0' );
- wp_enqueue_script( 'custom_wp_admin_script' );
- }
- add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_script' );
- add_filter( 'jpeg_quality', create_function( '', 'return 80;' ) );
- //buttons post box
- /* Fire our meta box setup function on the post editor screen. */
- add_action( 'load-post.php', 'smashing_post_meta_boxes_setup' );
- add_action( 'load-post-new.php', 'smashing_post_meta_boxes_setup' );
- /* Meta box setup function. */
- function smashing_post_meta_boxes_setup() {
- /* Add meta boxes on the 'add_meta_boxes' hook. */
- add_action( 'add_meta_boxes', 'smashing_add_post_meta_boxes' );
- }
- /* Create one or more meta boxes to be displayed on the post editor screen. */
- function smashing_add_post_meta_boxes() {
- $post_types = array ( 'post', 'Partners', 'News' , 'Events' , 'Lab' );
- add_meta_box(
- 'smashing-post-class', // Unique ID
- esc_html__( 'Post Class', 'example' ), // Title
- 'smashing_post_class_meta_box', // Callback function
- $post_types, // Admin page (or post type)
- 'side', // Context
- 'default' // Priority
- );
- }
- /* Display the post meta box. */
- function smashing_post_class_meta_box( $object, $box ) {
- ?>
- <?php wp_nonce_field( basename( __FILE__ ), 'smashing_post_class_nonce' ); ?>
- <p>
- <a class="post-btn-blue">Button</a>
- <br />
- <span class="short-blue">[buttonblue]Link Text[/buttonblue]</span>
- <br />
- </p>
- <?php
- }
- function buttonviolet_function( $atts, $content = null ) {
- return '<button class="post-btn-violet post-btn" type="button">'.do_shortcode($content).'</button>';
- }
- add_shortcode('buttonviolet', 'buttonviolet_function');
- function buttonblue_function( $atts, $content = null ) {
- return '<button class="post-btn-blue post-btn" type="button">'.do_shortcode($content).'</button>';
- }
- add_shortcode('buttonblue', 'buttonblue_function');
- //media frame scripts
- /*function media_script_enqueue() {
- wp_enqueue_script( 'media-script', get_template_directory_uri() . '/library/js/media-script.js', array( 'jquery', 'media-editor' ), '', true );
- }
- add_action( 'admin_enqueue_scripts', 'media_script_enqueue' ); // Back-end*/
- add_image_size( 'project-thumb', 360, 240, true );
- add_image_size( 'project-header', 800, 534, true );
- add_image_size( 'portrait', 263, 263, true );
- add_image_size( 'featured-story', 679, 457, true );
- //Posts register_nav_menus
- function revcon_change_post_label() {
- global $menu;
- global $submenu;
- $menu[5][0] = 'Projects';
- $submenu['edit.php'][5][0] = 'Projects';
- $submenu['edit.php'][10][0] = 'Add Project';
- $submenu['edit.php'][16][0] = 'Project Tags';
- }
- function revcon_change_post_object() {
- global $wp_post_types;
- $labels = &$wp_post_types['post']->labels;
- $labels->name = 'Projects';
- $labels->singular_name = 'Project';
- $labels->add_new = 'Add Projects';
- $labels->add_new_item = 'Add Projects';
- $labels->edit_item = 'Edit Projects';
- $labels->new_item = 'Projects';
- $labels->view_item = 'View Projects';
- $labels->search_items = 'Search Projects';
- $labels->not_found = 'No Projects found';
- $labels->not_found_in_trash = 'No Projects found in Trash';
- $labels->all_items = 'All Projects';
- $labels->menu_name = 'Projects';
- $labels->name_admin_bar = 'Projects';
- }
- add_action( 'admin_menu', 'revcon_change_post_label' );
- add_action( 'init', 'revcon_change_post_object' );
- $role_object = get_role( 'editor' );
- $role_object->add_cap( 'manage_options' );
- /*
- * Let Editors manage users, and run this only once.
- */
- function isa_editor_manage_users() {
- if ( get_option( 'isa_add_cap_editor_once' ) != 'done' ) {
- // let editor manage users
- $edit_editor = get_role('editor'); // Get the user role
- $edit_editor->add_cap('edit_users');
- $edit_editor->add_cap('list_users');
- $edit_editor->add_cap('promote_users');
- $edit_editor->add_cap('create_users');
- $edit_editor->add_cap('add_users');
- $edit_editor->add_cap('delete_users');
- update_option( 'isa_add_cap_editor_once', 'done' );
- }
- }
- add_action( 'init', 'isa_editor_manage_users' );
- //prevent editor from deleting, editing, or creating an administrator
- // only needed if the editor was given right to edit users
- class ISA_User_Caps {
- // Add our filters
- function ISA_User_Caps(){
- add_filter( 'editable_roles', array(&$this, 'editable_roles'));
- add_filter( 'map_meta_cap', array(&$this, 'map_meta_cap'),10,4);
- }
- // Remove 'Administrator' from the list of roles if the current user is not an admin
- function editable_roles( $roles ){
- if( isset( $roles['administrator'] ) && !current_user_can('administrator') ){
- unset( $roles['administrator']);
- }
- return $roles;
- }
- // If someone is trying to edit or delete an
- // admin and that user isn't an admin, don't allow it
- function map_meta_cap( $caps, $cap, $user_id, $args ){
- switch( $cap ){
- case 'edit_user':
- case 'remove_user':
- case 'promote_user':
- if( isset($args[0]) && $args[0] == $user_id )
- break;
- elseif( !isset($args[0]) )
- $caps[] = 'do_not_allow';
- $other = new WP_User( absint($args[0]) );
- if( $other->has_cap( 'administrator' ) ){
- if(!current_user_can('administrator')){
- $caps[] = 'do_not_allow';
- }
- }
- break;
- case 'delete_user':
- case 'delete_users':
- if( !isset($args[0]) )
- break;
- $other = new WP_User( absint($args[0]) );
- if( $other->has_cap( 'administrator' ) ){
- if(!current_user_can('administrator')){
- $caps[] = 'do_not_allow';
- }
- }
- break;
- default:
- break;
- }
- return $caps;
- }
- }
- $isa_user_caps = new ISA_User_Caps();
- add_action('pre_user_query','isa_pre_user_query');
- function isa_pre_user_query($user_search) {
- $user = wp_get_current_user();
- if ($user->ID!=1) { // Is not administrator, remove administrator
- global $wpdb;
- $user_search->query_where = str_replace('WHERE 1=1',
- "WHERE 1=1 AND {$wpdb->users}.ID<>1",$user_search->query_where);
- }
- }
- function dcg_password_form_fix() {
- global $post;
- $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
- $o = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
- ' . __( "To view the contents of this page, enter the password below:" ) . '
- <label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
- </form>
- ';
- return $o;
- }
- add_filter( 'the_password_form', 'dcg_password_form_fix' );
- function my_default_image_size () {
- return 'full size';
- }
- add_filter( 'pre_option_image_default_size', 'my_default_image_size' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement