__( 'Primary Menu', 'fruit-shake' ),
) );
/**
* Add default posts and comments RSS feed links to head
*/
add_theme_support( 'automatic-feed-links' );
/**
* Add support for custom backgrounds
*/
add_theme_support( 'custom-background' );
/**
* Add support for the Aside and Gallery Post Formats
*/
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link', 'image', 'status', 'quote' ) );
}
add_action( 'after_setup_theme', 'fruit_shake_setup' );
/**
* Enqueue scripts and styles.
*/
function fruit_shake_scripts() {
wp_enqueue_style( 'fruit-shake', get_stylesheet_uri() );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );
}
add_action( 'wp_enqueue_scripts', 'fruit_shake_scripts' );
/**
* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*/
function fruit_shake_page_menu_args($args) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'fruit_shake_page_menu_args' );
/**
* Register widgetized area and update sidebar with default widgets.
*/
function fruit_shake_widgets_init() {
register_sidebar( array (
'name' => __( 'Sidebar 1', 'fruit-shake' ),
'id' => 'sidebar-1',
'before_widget' => '',
'before_title' => '
',
) );
register_sidebar( array(
'name' => __( 'Footer Area One', 'fruit-shake' ),
'id' => 'sidebar-2',
'description' => __( 'An optional widget area for your site footer', 'fruit-shake' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Footer Area Two', 'fruit-shake' ),
'id' => 'sidebar-3',
'description' => __( 'An optional widget area for your site footer', 'fruit-shake' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Footer Area Three', 'fruit-shake' ),
'id' => 'sidebar-4',
'description' => __( 'An optional widget area for your site footer', 'fruit-shake' ),
'before_widget' => '',
'before_title' => '',
) );
}
add_action( 'widgets_init', 'fruit_shake_widgets_init' );
/**
* Add some useful default widgets to the Fruit Shake sidebar
*/
function fruit_shake_default_widgets() {
$sidebars = get_option( 'sidebars_widgets' );
if ( empty ( $sidebars['sidebar-1'] ) && isset( $_GET['activated'] ) ) {
update_option( 'widget_pages', array( 2 => array( 'title' => __( 'Menu', 'fruit-shake' ) ), '_multiwidget' => 1 ) );
update_option( 'widget_categories', array( 2 => array( 'title' => __( 'Topics', 'fruit-shake' ) ), '_multiwidget' => 1 ) );
update_option( 'widget_archives', array( 2 => array( 'title' => __( 'Archives', 'fruit-shake' ) ), '_multiwidget' => 1 ) );
update_option( 'widget_meta', array( 2 => array( 'title' => __( 'Meta', 'fruit-shake' ) ), '_multiwidget' => 1 ) );
update_option( 'sidebars_widgets', array(
'wp_inactive_widgets' => array(),
'sidebar-1' => array(
0 => 'pages-2',
1 => 'categories-2',
2 => 'archives-2',
3 => 'meta-2',
),
'array_version' => 3
) );
}
}
add_action( 'after_setup_theme', 'fruit_shake_default_widgets' );
/**
* Count the number of footer sidebars to enable dynamic classes for the footer.
*/
function fruit_shake_footer_sidebar_class() {
$count = 0;
if ( is_active_sidebar( 'sidebar-2' ) )
$count++;
if ( is_active_sidebar( 'sidebar-3' ) )
$count++;
if ( is_active_sidebar( 'sidebar-4' ) )
$count++;
$class = '';
switch ( $count ) {
case '1':
$class = 'one';
break;
case '2':
$class = 'two';
break;
case '3':
$class = 'three';
break;
}
if ( $class )
echo 'class="' . $class . '"';
}
/**
* Allow custom colors to clear the background image.
*/
function fruit_shake_custom_background_color() {
if ( get_background_image() == '' && get_background_color() != '' ) { ?>
' . __( 'Continue reading →', 'fruit-shake' ) . '';
}
/**
* Replaces "[...]" (appended to automatically generated excerpts) with an
* ellipsis and fruit_shake_continue_reading_link().
*
* To override this in a child theme, remove the filter and add your own
* function tied to the excerpt_more filter hook.
*/
function fruit_shake_auto_excerpt_more( $more ) {
return ' …' . fruit_shake_continue_reading_link();
}
add_filter( 'excerpt_more', 'fruit_shake_auto_excerpt_more' );
/**
* Adds a pretty "Continue Reading" link to custom post excerpts.
*
* To override this link in a child theme, remove the filter and add your own
* function tied to the get_the_excerpt filter hook.
*/
function fruit_shake_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= fruit_shake_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'fruit_shake_custom_excerpt_more' );
/**
* Grab the first URL from a Link post.
*/
function fruit_shake_url_grabber() {
if ( ! preg_match( '/]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
return false;
return esc_url_raw( $matches[1] );
}
/**
* Returns the current fruit shake theme options, with default values
* as fallback.
*/
function fruit_shake_get_theme_options() {
$defaults = array(
'fruit_scheme' => 'banana',
);
$options = get_option( 'fruit_shake_theme_options', $defaults );
return $options;
}
/**
* Returns the current fruit shake color scheme as selected in the
* theme options.
*/
function fruit_shake_current_fruit_scheme() {
$options = fruit_shake_get_theme_options();
return $options['fruit_scheme'];
}
/**
* Register our color schemes and add them to the queue.
*/
function fruit_shake_color_registrar() {
$fruit_scheme = fruit_shake_current_fruit_scheme();
if ( 'banana' == $fruit_scheme )
return;
wp_enqueue_style( $fruit_scheme, get_template_directory_uri() . '/colors/' . $fruit_scheme . '.css', null, null );
}
add_action( 'wp_enqueue_scripts', 'fruit_shake_color_registrar' );
/**
* Add special fruity classes to the WordPress body class.
*/
function fruit_shake_body_classes( $classes ) {
// We should always have content.
$classes[] = 'primary';
// If we have 1 sidebar active we have secondary content.
if ( is_active_sidebar( 'sidebar-1' ) )
$classes[] = 'secondary';
/**
* What's going on here?
* If there is a 'secondary' class we can override our basic CSS structure
* to make a 2-column layout adding some page width and some CSS to
* accommodate one widget area.
*/
// A useful class for styling Post Formats that aren't viewn as single posts.
if ( ! is_singular() )
$classes[] = 'indexed';
return $classes;
}
add_filter( 'body_class', 'fruit_shake_body_classes' );
/**
* Return the number of daily posts in the last week.
*/
function fruit_shake_daily_posts_in_last_week() {
global $wpdb;
$post_date = date( 'Y-m-d h:i:s', strtotime( '-1 weeks' ) );
$querystr = $wpdb->prepare(
"SELECT COUNT( DISTINCT ( SUBSTRING( post_date, 1, 10 ) ) ) FROM $wpdb->posts WHERE post_date > %s AND post_type = 'post'",
$post_date
);
$daily_posts_last_week = $wpdb->get_var( $querystr );
return (int) $daily_posts_last_week;
}
if ( ! function_exists( 'fruit_shake_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments
* template simply create your own fruit_shake_comment(), and that function
* will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* @since Fruit Shake 0.4
*/
function fruit_shake_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
id="li-comment-">
tag based on what is being viewed.
*
* @since Fruit Shake 1.0
*/
function fruit_shake_wp_title( $title, $sep ) {
global $page, $paged;
if ( is_feed() )
return $title;
// Add the blog name.
$title .= get_bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title .= " $sep $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
$title .= " $sep " . sprintf( __( 'Page %s', 'fruit-shake' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'fruit_shake_wp_title', 10, 2 );
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Load up our theme options.
*/
require get_template_directory() . '/inc/theme-options/theme-options.php';
/**
* Load up our fruitylicious custom widget.
*/
require get_template_directory() . '/inc/widgets.php';
/**
* Get first image from the_content()
*/
function fruit_shake_get_first_image( $content ) {
$images = array();
preg_match_all( '!!iUs', $content, $matches );
if ( !empty( $matches[1] ) ) {
foreach ( $matches[1] as $match ) {
if ( stristr( $match, '/smilies/' ) )
continue;
$images[] = array(
'type' => 'image',
'from' => 'html',
'src' => html_entity_decode( $match ),
'href' => '', // No link to apply to these. Might potentially parse for that as well, but not for now
);
}
return $images[0]; //Return the first image
}
}
/**
* This theme was built with PHP, Semantic HTML, CSS, love, and a Toolbox.
*/