diff options
| author | Max | 2017-05-18 14:03:27 +0200 |
|---|---|---|
| committer | Max | 2017-05-18 14:03:27 +0200 |
| commit | f597e2fe949a1e18eb778b9a5bd102de88570555 (patch) | |
| tree | 7e42e6f91dd3e764cd2cf0c4f61f48501c2ed98f /inc | |
| download | docs.maxmail.xyz-f597e2fe949a1e18eb778b9a5bd102de88570555.tar.gz | |
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/bootstrap-wp-navwalker.php | 223 | ||||
| -rw-r--r-- | inc/custom-comments.php | 30 | ||||
| -rw-r--r-- | inc/customizer.php | 63 | ||||
| -rw-r--r-- | inc/enqueue.php | 47 | ||||
| -rw-r--r-- | inc/extras.php | 26 | ||||
| -rw-r--r-- | inc/jetpack.php | 38 | ||||
| -rw-r--r-- | inc/setup.php | 100 | ||||
| -rw-r--r-- | inc/template-tags.php | 123 | ||||
| -rw-r--r-- | inc/widgets.php | 50 | ||||
| -rw-r--r-- | inc/wpcom.php | 29 |
10 files changed, 729 insertions, 0 deletions
diff --git a/inc/bootstrap-wp-navwalker.php b/inc/bootstrap-wp-navwalker.php new file mode 100644 index 0000000..d175e56 --- /dev/null +++ b/inc/bootstrap-wp-navwalker.php @@ -0,0 +1,223 @@ +<?php +/** +* +* Adapted from Edward McIntyre's wp_bootstrap_navwalker class. +* Removed support for glyphicon and added support for Font Awesome +* +*/ +/** + * Class Name: wp_bootstrap_navwalker + * GitHub URI: https://github.com/twittem/wp-bootstrap-navwalker + * Description: A custom WordPress nav walker class to implement the Bootstrap 3 navigation style in a custom theme using the WordPress built in menu manager. + * Version: 2.0.4 + * Author: Edward McIntyre - @twittem + * License: GPL-2.0+ + * License URI: http://www.gnu.org/licenses/gpl-2.0.txt + * @package understrap + */ +//exit if accessed directly +if(!defined('ABSPATH')) exit; + +class wp_bootstrap_navwalker extends Walker_Nav_Menu { + + /** + * @see Walker::start_lvl() + * @since 3.0.0 + * + * @param string $output Passed by reference. Used to append additional content. + * @param int $depth Depth of page. Used for padding. + */ + public function start_lvl( &$output, $depth = 0, $args = array() ) { + $indent = str_repeat( "\t", $depth ); + $output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu\">\n"; + } + + /** + * @see Walker::start_el() + * @since 3.0.0 + * + * @param string $output Passed by reference. Used to append additional content. + * @param object $item Menu item data object. + * @param int $depth Depth of menu item. Used for padding. + * @param int $current_page Menu item ID. + * @param object $args + */ + public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { + $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; + + /** + * Dividers, Headers or Disabled + * ============================= + * Determine whether the item is a Divider, Header, Disabled or regular + * menu item. To prevent errors we use the strcasecmp() function to so a + * comparison that is not case sensitive. The strcasecmp() function returns + * a 0 if the strings are equal. + */ + if ( strcasecmp( $item->attr_title, 'divider' ) == 0 && $depth === 1 ) { + $output .= $indent . '<li role="presentation" class="divider">'; + } else if ( strcasecmp( $item->title, 'divider') == 0 && $depth === 1 ) { + $output .= $indent . '<li role="presentation" class="divider">'; + } else if ( strcasecmp( $item->attr_title, 'dropdown-header') == 0 && $depth === 1 ) { + $output .= $indent . '<li role="presentation" class="dropdown-header">' . esc_attr( $item->title ); + } else if ( strcasecmp($item->attr_title, 'disabled' ) == 0 ) { + $output .= $indent . '<li role="presentation" class="disabled"><a href="#">' . esc_attr( $item->title ) . '</a>'; + } else { + + $class_names = $value = ''; + + $classes = empty( $item->classes ) ? array() : (array) $item->classes; + $classes[] = 'nav-item menu-item-' . $item->ID; + + $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); + + /* + if ( $args->has_children ) + $class_names .= ' dropdown'; + */ + + if($args->has_children && $depth === 0) { $class_names .= ' dropdown'; } elseif($args->has_children && $depth > 0) { $class_names .= ' dropdown-submenu'; } + + if ( in_array( 'current-menu-item', $classes ) ) + $class_names .= ' active'; + + // remove Font Awesome icon from classes array and save the icon + // we will add the icon back in via a <span> below so it aligns with + // the menu item + if ( in_array('fa', $classes)) { + $key = array_search('fa', $classes); + $icon = $classes[$key + 1]; + $class_names = str_replace($classes[$key+1], '', $class_names); + $class_names = str_replace($classes[$key], '', $class_names); + + } + + $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; + + $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); + $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; + + $output .= $indent . '<li' . $id . $value . $class_names .'>'; + + $atts = array(); + $atts['title'] = ! empty( $item->title ) ? $item->title : ''; + $atts['target'] = ! empty( $item->target ) ? $item->target : ''; + $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; + + // If item has_children add atts to a. + // if ( $args->has_children && $depth === 0 ) { + if ( $args->has_children && $depth === 0 ) { + $atts['href'] = '#'; + $atts['data-toggle'] = 'dropdown'; + $atts['class'] = 'dropdown-toggle'; + } else { + $atts['href'] = ! empty( $item->url ) ? $item->url : ''; + } + + $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args ); + + $attributes = ''; + foreach ( $atts as $attr => $value ) { + if ( ! empty( $value ) ) { + $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); + $attributes .= ' ' . $attr . '="' . $value . '"'; + } + } + + $item_output = $args->before; + + // Font Awesome icons + if ( ! empty( $icon ) ) + $item_output .= '<a'. $attributes .'><span class="fa ' . esc_attr( $icon ) . '"></span> '; + else + $item_output .= '<a'. $attributes .'>'; + + $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; + $item_output .= ( $args->has_children && 0 === $depth ) ? ' <span class="caret"></span></a>' : '</a>'; + $item_output .= $args->after; + + $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); + } + } + + /** + * Traverse elements to create list from elements. + * + * Display one element if the element doesn't have any children otherwise, + * display the element and its children. Will only traverse up to the max + * depth and no ignore elements under that depth. + * + * This method shouldn't be called directly, use the walk() method instead. + * + * @see Walker::start_el() + * @since 2.5.0 + * + * @param object $element Data object + * @param array $children_elements List of elements to continue traversing. + * @param int $max_depth Max depth to traverse. + * @param int $depth Depth of current element. + * @param array $args + * @param string $output Passed by reference. Used to append additional content. + * @return null Null on failure with no changes to parameters. + */ + public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { + if ( ! $element ) + return; + + $id_field = $this->db_fields['id']; + + // Display this element. + if ( is_object( $args[0] ) ) + $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); + + parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); + } + + /** + * Menu Fallback + * ============= + * If this function is assigned to the wp_nav_menu's fallback_cb variable + * and a manu has not been assigned to the theme location in the WordPress + * menu manager the function with display nothing to a non-logged in user, + * and will add a link to the WordPress menu manager if logged in as an admin. + * + * @param array $args passed from the wp_nav_menu function. + * + */ + public static function fallback( $args ) { + if ( current_user_can( 'manage_options' ) ) { + + extract( $args ); + + $fb_output = null; + + if ( $container ) { + $fb_output = '<' . $container; + + if ( $container_id ) + $fb_output .= ' id="' . $container_id . '"'; + + if ( $container_class ) + $fb_output .= ' class="' . $container_class . '"'; + + $fb_output .= '>'; + } + + $fb_output .= '<ul'; + + if ( $menu_id ) + $fb_output .= ' id="' . $menu_id . '"'; + + if ( $menu_class ) + $fb_output .= ' class="' . $menu_class . '"'; + + $fb_output .= '>'; + $fb_output .= '<li><a href="' . admin_url( 'nav-menus.php' ) . '">Add a menu</a></li>'; + $fb_output .= '</ul>'; + + if ( $container ) + $fb_output .= '</' . $container . '>'; + + echo $fb_output; + } + } +} diff --git a/inc/custom-comments.php b/inc/custom-comments.php new file mode 100644 index 0000000..32f2d2e --- /dev/null +++ b/inc/custom-comments.php @@ -0,0 +1,30 @@ +<?php +/************* COMMENT LAYOUT *********************/ +// Comment Form + + add_filter( 'comment_form_default_fields', 'bootstrap3_comment_form_fields' ); + function bootstrap3_comment_form_fields( $fields ) { + $commenter = wp_get_current_commenter(); + $req = get_option( 'require_name_email' ); + $aria_req = ( $req ? " aria-required='true'" : '' ); + $html5 = current_theme_supports( 'html5', 'comment-form' ) ? 1 : 0; + $fields = array( + 'author' => '<div class="form-group comment-form-author">' . '<label for="author">' . __( 'Name', 'understrap' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . + '<input class="form-control" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></div>', + 'email' => '<div class="form-group comment-form-email"><label for="email">' . __( 'Email', 'understrap' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . + '<input class="form-control" id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div>', + 'url' => '<div class="form-group comment-form-url"><label for="url">' . __( 'Website', 'understrap' ) . '</label> ' . + '<input class="form-control" id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div>', + ); + return $fields; + } + + add_filter( 'comment_form_defaults', 'bootstrap3_comment_form' ); + function bootstrap3_comment_form( $args ) { + $args['comment_field'] = '<div class="form-group comment-form-comment"> + <label for="comment">' . _x( 'Comment', 'noun', 'understrap' ) . ( ' <span class="required">*</span>' ) . '</label> + <textarea class="form-control" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea> + </div>'; + $args['class_submit'] = 'btn btn-default'; // since WP 4.1 + return $args; + } diff --git a/inc/customizer.php b/inc/customizer.php new file mode 100644 index 0000000..fc7886b --- /dev/null +++ b/inc/customizer.php @@ -0,0 +1,63 @@ +<?php +/** + * understrap Theme Customizer + * + * @package understrap + */ + +/** + * Add postMessage support for site title and description for the Theme Customizer. + * + * @param WP_Customize_Manager $wp_customize Theme Customizer object. + */ +function understrap_customize_register( $wp_customize ) { + $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; + $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; + +} +add_action( 'customize_register', 'understrap_customize_register' ); + +function understrap_theme_customize_register( $wp_customize ) { + + $wp_customize->add_section( 'understrap_theme_slider_options', array( + 'title' => __( 'Slider Settings', 'understrap' ) + ) ); + + $wp_customize->add_setting( 'understrap_theme_slider_count_setting', array( + 'default' => '1', + 'sanitize_callback' => 'absint' + ) ); + + $wp_customize->add_control( 'understrap_theme_slider_count', array( + 'label' => __( 'Number of slides displaying at once', 'understrap' ), + 'section' => 'understrap_theme_slider_options', + 'type' => 'text', + 'settings' => 'understrap_theme_slider_count_setting' + ) ); + + $wp_customize->add_setting( 'understrap_theme_slider_time_setting', array( + 'default' => '5000', + 'sanitize_callback' => 'absint' + ) ); + + $wp_customize->add_control( 'understrap_theme_slider_time', array( + 'label' => __( 'Slider Time (in ms)', 'understrap' ), + 'section' => 'understrap_theme_slider_options', + 'type' => 'text', + 'settings' => 'understrap_theme_slider_time_setting' + ) ); + + +} +add_action( 'customize_register', 'understrap_theme_customize_register' ); + + + +/** + * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. + */ +function understrap_customize_preview_js() { + wp_enqueue_script( 'understrap_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true ); +} +add_action( 'customize_preview_init', 'understrap_customize_preview_js' ); diff --git a/inc/enqueue.php b/inc/enqueue.php new file mode 100644 index 0000000..a84698f --- /dev/null +++ b/inc/enqueue.php @@ -0,0 +1,47 @@ +<?php +/** + * understrap enqueue scripts + * + * @package understrap + */ + + +function understrap_scripts() { + wp_enqueue_style( 'understrap-styles', get_stylesheet_directory_uri() . '/css/theme.min.css', array(), '0.3.9'); + wp_enqueue_style( 'bootstrap-material-design', get_template_directory_uri() .'/css/bootstrap-material-design.min.css',array(),'0.5.10' ); + wp_enqueue_style( 'bootstrap-material-design-ripples', get_template_directory_uri() .'/css/ripples.min.css',array(),'0.5.10' ); + + wp_enqueue_script('jquery'); + wp_enqueue_script( 'understrap-scripts', get_template_directory_uri() . '/js/theme.min.js', array(), '0.3.9', true ); + + if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { + wp_enqueue_script( 'comment-reply' ); + } +} + +add_action( 'wp_enqueue_scripts', 'understrap_scripts' ); + +/** +*Loading slider script conditionally +**/ + +if ( is_active_sidebar( 'hero' ) ): +add_action("wp_enqueue_scripts","understrap_slider"); + +function understrap_slider(){ + if ( is_front_page() ) { + $data = array( + "timeout"=> intval( get_theme_mod( 'understrap_theme_slider_time_setting', 5000 )), + "items"=> intval( get_theme_mod( 'understrap_theme_slider_count_setting', 1 )) + ); + + + wp_enqueue_script("understrap-slider-script", get_stylesheet_directory_uri() . '/js/slider_settings.js', array(), '0.3.9'); + wp_localize_script( "understrap-slider-script", "understrap_slider_variables", $data ); + } +} +endif; + + + + diff --git a/inc/extras.php b/inc/extras.php new file mode 100644 index 0000000..5e7aecf --- /dev/null +++ b/inc/extras.php @@ -0,0 +1,26 @@ +<?php +/** + * Custom functions that act independently of the theme templates. + * + * Eventually, some of the functionality here could be replaced by core features. + * + * @package understrap + */ +/** + * Adds custom classes to the array of body classes. + * + * @param array $classes Classes for the body element. + * @return array + */ +function understrap_body_classes( $classes ) { + // Adds a class of group-blog to blogs with more than 1 published author. + if ( is_multi_author() ) { + $classes[] = 'group-blog'; + } + // Adds a class of hfeed to non-singular pages. + if ( ! is_singular() ) { + $classes[] = 'hfeed'; + } + return $classes; +} +add_filter( 'body_class', 'understrap_body_classes' ); diff --git a/inc/jetpack.php b/inc/jetpack.php new file mode 100644 index 0000000..6a0a3ea --- /dev/null +++ b/inc/jetpack.php @@ -0,0 +1,38 @@ +<?php +/** + * Jetpack Compatibility File. + * + * @link https://jetpack.com/ + * + * @package understrap + */ +/** + * Jetpack setup function. + * + * See: https://jetpack.com/support/infinite-scroll/ + * See: https://jetpack.com/support/responsive-videos/ + */ +function understrap_jetpack_setup() { + // Add theme support for Infinite Scroll. + add_theme_support( 'infinite-scroll', array( + 'container' => 'main', + 'render' => 'understrap_infinite_scroll_render', + 'footer' => 'page', + ) ); + // Add theme support for Responsive Videos. + add_theme_support( 'jetpack-responsive-videos' ); +} +add_action( 'after_setup_theme', 'understrap_jetpack_setup' ); +/** + * Custom render function for Infinite Scroll. + */ +function understrap_infinite_scroll_render() { + while ( have_posts() ) { + the_post(); + if ( is_search() ) : + get_template_part( 'loop-templates/content', 'search' ); + else : + get_template_part( 'loop-templates/content', get_post_format() ); + endif; + } +} diff --git a/inc/setup.php b/inc/setup.php new file mode 100644 index 0000000..622c570 --- /dev/null +++ b/inc/setup.php @@ -0,0 +1,100 @@ +<?php +/** + * Set the content width based on the theme's design and stylesheet. + * @package understrap + */ +if ( ! isset( $content_width ) ) { + $content_width = 640; /* pixels */ +} + +if ( ! function_exists( 'understrap_setup' ) ) : +/** + * Sets up theme defaults and registers support for various WordPress features. + * + * Note that this function is hooked into the after_setup_theme hook, which + * runs before the init hook. The init hook is too late for some features, such + * as indicating support for post thumbnails. + */ +function understrap_setup() { + + /* + * Make theme available for translation. + * Translations can be filed in the /languages/ directory. + * If you're building a theme based on understrap, use a find and replace + * to change 'understrap' to the name of your theme in all the template files + */ + load_theme_textdomain( 'understrap', get_template_directory() . '/languages' ); + + // Add default posts and comments RSS feed links to head. + add_theme_support( 'automatic-feed-links' ); + + /* + * Let WordPress manage the document title. + * By adding theme support, we declare that this theme does not use a + * hard-coded <title> tag in the document head, and expect WordPress to + * provide it for us. + */ + add_theme_support( 'title-tag' ); + + /* + * Enable support for Post Thumbnails on posts and pages. + * + * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails + */ + //add_theme_support( 'post-thumbnails' ); + + // This theme uses wp_nav_menu() in one location. + register_nav_menus( array( + 'primary' => __( 'Primary Menu', 'understrap' ), + ) ); + + /* + * Switch default core markup for search form, comment form, and comments + * to output valid HTML5. + */ + add_theme_support( 'html5', array( + 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', + ) ); + + /* + * Adding Thumbnail basic support + */ + add_theme_support( "post-thumbnails" ); + + /* + * Enable support for Post Formats. + * See http://codex.wordpress.org/Post_Formats + */ + add_theme_support( 'post-formats', array( + 'aside', 'image', 'video', 'quote', 'link', + ) ); + + // Set up the WordPress core custom background feature. + add_theme_support( 'custom-background', apply_filters( 'understrap_custom_background_args', array( + 'default-color' => 'ffffff', + 'default-image' => '', + ) ) ); +} +endif; // understrap_setup +add_action( 'after_setup_theme', 'understrap_setup' ); + +/** +* Adding the Read more link to excerpts +*/ +/*function new_excerpt_more( $more ) { + return ' <p><a class="read-more btn btn-default" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'understrap') . '</a></p>'; +} +add_filter( 'excerpt_more', 'new_excerpt_more' );*/ +/* Removes the ... from the excerpt read more link */ +function custom_excerpt_more( $more ) { + return ''; +} +add_filter( 'excerpt_more', 'custom_excerpt_more' ); + +/* Adds a custom read more link to all excerpts, manually or automatically generated */ + +function all_excerpts_get_more_link($post_excerpt) { + + return $post_excerpt . ' [...]<p><a class="btn btn-default understrap-read-more-link" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More...', 'understrap') . '</a></p>'; +} +add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link'); diff --git a/inc/template-tags.php b/inc/template-tags.php new file mode 100644 index 0000000..067155e --- /dev/null +++ b/inc/template-tags.php @@ -0,0 +1,123 @@ +<?php +/** + * Custom template tags for this theme. + * + * Eventually, some of the functionality here could be replaced by core features. + * + * @package understrap + */ + + +if ( ! function_exists( 'understrap_posted_on' ) ) : +/** + * Prints HTML with meta information for the current post-date/time and author. + */ +function understrap_posted_on() { + $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; + if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { + $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; + } + + $time_string = sprintf( $time_string, + esc_attr( get_the_date( 'c' ) ), + esc_html( get_the_date() ), + esc_attr( get_the_modified_date( 'c' ) ), + esc_html( get_the_modified_date() ) + ); + + $posted_on = sprintf( + esc_html_x( 'Posted on %s', 'post date', 'understrap' ), + '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>' + ); + + $byline = sprintf( + esc_html_x( 'by %s', 'post author', 'understrap' ), + '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>' + ); + + echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; + +} +endif; + +if ( ! function_exists( 'understrap_entry_footer' ) ) : +/** + * Prints HTML with meta information for the categories, tags and comments. + */ +function understrap_entry_footer() { + // Hide category and tag text for pages. + if ( 'post' == get_post_type() ) { + /* translators: used between list items, there is a space after the comma */ + $categories_list = get_the_category_list( __( ', ', 'understrap' ) ); + if ( $categories_list && understrap_categorized_blog() ) { + printf( '<span class="cat-links">' . __( 'Posted in %1$s', 'understrap' ) . '</span>', $categories_list ); + } + + /* translators: used between list items, there is a space after the comma */ + $tags_list = get_the_tag_list( '', __( ', ', 'understrap' ) ); + if ( $tags_list ) { + printf( '<span class="tags-links">' . __( 'Tagged %1$s', 'understrap' ) . '</span>', $tags_list ); + } + } + + if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { + echo '<span class="comments-link">'; + comments_popup_link( __( 'Leave a comment', 'understrap' ), __( '1 Comment', 'understrap' ), __( '% Comments', 'understrap' ) ); + echo '</span>'; + } + + edit_post_link( + sprintf( + /* translators: %s: Name of current post */ + esc_html__( 'Edit %s', 'understrap' ), + the_title( '<span class="screen-reader-text">"', '"</span>', false ) + ), + '<span class="edit-link">', + '</span>' + ); +} +endif; + +/** + * Returns true if a blog has more than 1 category. + * + * @return bool + */ +function understrap_categorized_blog() { + if ( false === ( $all_the_cool_cats = get_transient( 'understrap_categories' ) ) ) { + // Create an array of all the categories that are attached to posts. + $all_the_cool_cats = get_categories( array( + 'fields' => 'ids', + 'hide_empty' => 1, + + // We only need to know if there is more than one category. + 'number' => 2, + ) ); + + // Count the number of categories that are attached to the posts. + $all_the_cool_cats = count( $all_the_cool_cats ); + + set_transient( 'understrap_categories', $all_the_cool_cats ); + } + + if ( $all_the_cool_cats > 1 ) { + // This blog has more than 1 category so understrap_categorized_blog should return true. + return true; + } else { + // This blog has only 1 category so understrap_categorized_blog should return false. + return false; + } +} + +/** + * Flush out the transients used in understrap_categorized_blog. + */ +function understrap_category_transient_flusher() { + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { + return; + } + // Like, beat it. Dig? + delete_transient( 'understrap_categories' ); +} +add_action( 'edit_category', 'understrap_category_transient_flusher' ); +add_action( 'save_post', 'understrap_category_transient_flusher' ); diff --git a/inc/widgets.php b/inc/widgets.php new file mode 100644 index 0000000..38aff3d --- /dev/null +++ b/inc/widgets.php @@ -0,0 +1,50 @@ +<?php +/** + * Declaring widgets + * + * + * @package understrap + */ +function understrap_widgets_init() { + register_sidebar( array( + 'name' => __( 'Sidebar', 'understrap' ), + 'id' => 'sidebar-1', + 'description' => 'Sidebar widget area', + 'before_widget' => '<aside id="%1$s" class="widget %2$s">', + 'after_widget' => '</aside>', + 'before_title' => '<h3 class="widget-title">', + 'after_title' => '</h3>', + ) ); + + register_sidebar( array( + 'name' => __( 'Hero Slider', 'understrap' ), + 'id' => 'hero', + 'description' => 'Hero slider area. Place two or more widgets here and they will slide!', + 'before_widget' => '<div class="jumbotron"><div class="container"><div class="row"><div class="item"><div class="col-md-12">', + 'after_widget' => '</div></div></div></div></div>', + 'before_title' => '', + 'after_title' => '', + ) ); + + register_sidebar( array( + 'name' => __( 'Hero Static', 'understrap' ), + 'id' => 'statichero', + 'description' => 'Static Hero widget. no slider functionallity', + 'before_widget' => '', + 'after_widget' => '', + 'before_title' => '', + 'after_title' => '', + ) ); + + register_sidebar( array( + 'name' => __( 'Footer Full', 'understrap' ), + 'id' => 'footerfull', + 'description' => 'Widget area below main content and above footer', + 'before_widget' => '', + 'after_widget' => '', + 'before_title' => '', + 'after_title' => '', + ) ); + +} +add_action( 'widgets_init', 'understrap_widgets_init' );
\ No newline at end of file diff --git a/inc/wpcom.php b/inc/wpcom.php new file mode 100644 index 0000000..8400caa --- /dev/null +++ b/inc/wpcom.php @@ -0,0 +1,29 @@ +<?php +/** + * WordPress.com-specific functions and definitions. + * + * This file is centrally included from `wp-content/mu-plugins/wpcom-theme-compat.php`. + * + * @package understrap + */ + +/** + * Adds support for wp.com-specific theme functions. + * + * @global array $themecolors + */ +function understrap_wpcom_setup() { + global $themecolors; + + // Set theme colors for third party services. + if ( ! isset( $themecolors ) ) { + $themecolors = array( + 'bg' => '', + 'border' => '', + 'text' => '', + 'link' => '', + 'url' => '', + ); + } +} +add_action( 'after_setup_theme', 'understrap_wpcom_setup' ); |
