.
* Author Contact: info@backmybook.com
* Free Wordpress Theme for Authors URL: http://backmybook.com/free-wordpress-theme-authors
*
*
* @package WordPress
* @subpackage Back_My_Book
* @since Back My Book 1.0
*/
// ========= START LOADING SETTINGS AND CLASSES =========
/** Tell WordPress to run backmybook_setup() when the 'after_setup_theme' hook is run. */
add_action( 'after_setup_theme', 'backmybook_setup' );
define('WP_VERSION', $wp_version);
if ( ! function_exists( 'backmybook_setup' ) ):
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* @uses add_theme_support() To add support for post thumbnails and automatic feed links.
* @uses register_nav_menus() To add support for navigation menus.
* @uses set_post_thumbnail_size() To set a custom post thumbnail size.
*
* @since Back My Book 1.0
*/
function backmybook_setup() {
// Checks to see if WordPress installation is compatible with theme
if (WP_VERSION < 3.0): // disable theme front end if wp < 3.0
function bmb_unsupported_wp_version(){ ?>
__( 'Primary Navigation', 'backmybook' ),
'footer' => __( 'Footer Navigation', 'backmybook' )
) );
// Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
register_default_headers( array(
'default' => array(
'url' => '%s/images/headers/path.png',
'thumbnail_url' => '%s/images/headers/path-thumbnail.png',
/* translators: header image description */
'description' => __( 'Default', 'backmybook' )
),
'black' => array(
'url' => '%s/images/headers/black.jpg',
'thumbnail_url' => '%s/images/headers/black-thumbnail.jpg',
/* translators: header image description */
'description' => __( 'Black', 'backmybook' )
),
'tile' => array(
'url' => '%s/images/headers/tile.gif',
'thumbnail_url' => '%s/images/headers/tile-thumbnail.jpg',
/* translators: header image description */
'description' => __( 'Tile', 'backmybook' )
),
'books' => array(
'url' => '%s/images/headers/books.jpg',
'thumbnail_url' => '%s/images/headers/books-thumbnail.jpg',
/* translators: header image description */
'description' => __( 'Books', 'backmybook' )
),
'dots' => array(
'url' => '%s/images/headers/dots.gif',
'thumbnail_url' => '%s/images/headers/dots-thumbnail.jpg',
/* translators: header image description */
'description' => __( 'Dots', 'backmybook' )
),
'flowers' => array(
'url' => '%s/images/headers/flowers.jpg',
'thumbnail_url' => '%s/images/headers/flowers-thumbnail.jpg',
/* translators: header image description */
'description' => __( 'Flowers', 'backmybook' )
),
'tile-gray' => array(
'url' => '%s/images/headers/tile-gray.gif',
'thumbnail_url' => '%s/images/headers/tile-gray-thumbnail.jpg',
/* translators: header image description */
'description' => __( 'Tile Gray', 'backmybook' )
),
'tile-orange' => array(
'url' => '%s/images/headers/tile-orange.jpg',
'thumbnail_url' => '%s/images/headers/tile-orange-thumbnail.jpg',
/* translators: header image description */
'description' => __( 'Tile Orange', 'backmybook' )
)
) );
// Sets the defualt colors for theme
$bmb_theme_color_defaults = array(
'bmb_text_links' => array('value' => 'B58A00','css' =>'a:link, a:visited, a:hover {color:#'),
'bmb_top_menu' => array('value' =>'59503E','css' =>'#nav,#nav ul ul a {background-color:#'),
'bmb_body_text' => array('value' => '111111','css' =>'body, input, textarea {color:#'),
'bmb_top_menu_hover' => array('value' => 'FFFFFF','css' =>'#nav li:hover > a,#nav ul ul :hover > a {color:#'),
'bmb_top_menu_selected' => array('value' => 'FAF3CF', 'css' =>'#nav ul li.current_page_item > a, #nav ul li.current-menu-ancestor > a, #nav ul li.current-menu-item > a, #nav ul li.current-menu-parent > a {color:#'),
'bmb_top_menu_unselected' => array('value' => 'BAAE8D','css' =>'#nav a {color:#'),
'bmb_author_name' => array('value' => 'FFFFFF','css' =>'.logo a {color:#'),
'bmb_author_description' => array('value' => 'FAF3CF','css' =>'.site-description {color:#'),
'bmb_page_title_h1' => array('value' => 'FFFFFF','css' =>'h1.entry-title {color:#'),
'bmb_page_title_h1_bg' => array('value' => '333333','css' =>'h1.entry-title {background-color:#'),
'bmb_category_title_h1' => array('value' => '333333','css' =>'h1.page-title {background-color:#'),
'bmb_page_title_h2' => array('value' => 'B58A00','css' =>'h2 a:link, h2 a:visited {color:#'),
'bmb_content_titles' => array('value' => 'B58A00','css' =>'.entry-content h1,.entry-content h2, .entry-content h3, .entry-content h4, .entry-content h5, .entry-content h6 {color:#'),
'bmb_footer_text' => array('value' => 'FFFFFF','css' =>'.footer-links li a,.footer-copy {color:#'),
'bmb_footer_bg' => array('value' => '000000','css' =>'#site-info {background-color:#')
);
// Now add default colors to database.
add_option('bmb_theme_colors', $bmb_theme_color_defaults);
$bmb_theme_font = array(
'value' => 'Candara, Verdana, sans-serif',
'css' => 'body { font-family: ',
'key' => 'candara'
);
// Now add the default font to database.
add_option('bmb_theme_font', $bmb_theme_font);
// Make sure the auto generated css file for custom color settings exits
if (!file_exists($file = TEMPLATEPATH.'/css/custom-colors.css')) {
$fh = fopen($file, 'w');
fwrite($fh,$data);
fclose($fh);
}
endif;
}
endif;
/**
* Add custom style sheets and reset file
**/
if (!is_admin()) {
wp_enqueue_style( 'bmb-reset-fonts-grids', get_stylesheet_directory_uri() . '/css/reset-fonts-grids.css');
wp_enqueue_style( 'bmb-main', get_stylesheet_directory_uri() . '/style.css');
wp_enqueue_style( 'bmb-custom-colors', get_stylesheet_directory_uri() . '/css/custom-colors.css');
}
/**
* Makes some changes to the tag, by filtering the output of wp_title().
*
* If we have a site description and we're viewing the home page or a blog posts
* page (when using a static front page), then we will add the site description.
*
* If we're viewing a search result, then we're going to recreate the title entirely.
* We're going to add page numbers to all titles as well, to the middle of a search
* result title and the end of all other titles.
*
* The site title also gets added to all titles.
*
* @since Back My Book 1.0
*
* @param string $title Title generated by wp_title()
* @param string $separator The separator passed to wp_title(). Back My Book uses a
* vertical bar, "|", as a separator in header.php.
* @return string The new title, ready for the tag.
* @author WordPress Team
*/
function backmybook_filter_wp_title( $title, $separator ) {
// Don't affect wp_title() calls in feeds.
if ( is_feed() )
return $title;
// The $paged global variable contains the page number of a listing of posts.
// The $page global variable contains the page number of a single post that is paged.
// We'll display whichever one applies, if we're not looking at the first page.
global $paged, $page;
if ( is_search() ) {
// If we're a search, let's start over:
$title = sprintf( __( 'Search results for %s', 'backmybook' ), '"' . get_search_query() . '"' );
// Add a page number if we're on page 2 or more:
if ( $paged >= 2 )
$title .= " $separator " . sprintf( __( 'Page %s', 'backmybook' ), $paged );
// Add the site name to the end:
$title .= " $separator " . get_bloginfo( 'name', 'display' );
// We're done. Let's send the new title back to wp_title():
return $title;
}
// Otherwise, let's start by adding the site name to the end:
$title .= get_bloginfo( 'name', 'display' );
// If we have a site description and we're on the home/front page, add the description:
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title .= " $separator " . $site_description;
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
$title .= " $separator " . sprintf( __( 'Page %s', 'backmybook' ), max( $paged, $page ) );
// Return the new title to wp_title():
return $title;
}
add_filter( 'wp_title', 'backmybook_filter_wp_title', 10, 2 );
/**
* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*
* @since Twenty Ten 1.0
* @author WordPress Team
*/
function backmybook_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'backmybook_page_menu_args' );
/**
* Sets the post excerpt length to 40 characters.
*
* @since Back My Book 1.0
* @return int
* @author WordPress Team
*/
function backmybook_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'backmybook_excerpt_length' );
/**
* Returns a "Continue Reading" link for excerpts
*
* @since Back My Book 1.0
* @return string "Continue Reading" link
* @author Based WordPress Team Twenty Ten theme
*/
function backmybook_continue_reading_link() {
return '
';
}
/**
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and backmybook_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.
*
* @since Back My Book 1.0
* @return string An ellipsis
* @author WordPress Team
*/
function backmybook_auto_excerpt_more( $more ) {
return ' …' . backmybook_continue_reading_link();
}
add_filter( 'excerpt_more', 'backmybook_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.
*
* @since Back My Book 1.0
* @return string Excerpt with a pretty "Continue Reading" link
* @author WordPress Team
*/
function backmybook_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= backmybook_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'backmybook_custom_excerpt_more' );
/**
* Register widgetized areas, including sidebars.
*
* @since Back MyBook 1.0
* @uses register_sidebar
*/
function backmybook_widgets_init() {
// Area 1, located at the top right of the layout.
register_sidebar( array(
'name' => __( 'BmB Left Sidebar 1', 'backmybook' ),
'id' => 'primary-widget-area',
'description' => __( 'The primary widget area', 'backmybook' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '
',
'after_title' => '
',
) );
// Area 2, located below the Primary Widget Area in the left sidebar. Empty by default.
register_sidebar( array(
'name' => __( 'BmB Left Sidebar 2', 'backmybook' ),
'id' => 'secondary-widget-area',
'description' => __( 'The secondary widget area', 'backmybook' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '
',
'after_title' => '
',
) );
// Area 3, located at the top right of the layout. Empty by default.
register_sidebar( array(
'name' => __( 'BmB Right Sidebar 1', 'backmybook' ),
'id' => 'right-primary-widget-area',
'description' => __( 'Right primary sidebar widget area', 'backmybook' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '
',
'after_title' => '
',
) );
// Area 4, located below the primary widget in the right sidebar. Empty by default.
register_sidebar( array(
'name' => __( 'BmB Right Sidebar 2', 'backmybook' ),
'id' => 'right-secondary-widget-area',
'description' => __( 'Right sidebar secondary widget area', 'backmybook' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '
',
'after_title' => '
',
) );
}
/** Register sidebars by running backmybook_widgets_init() on the widgets_init hook. */
add_action( 'widgets_init', 'backmybook_widgets_init' );
// Set sepcial widget to display customized data in sidebars.
class List_Content extends WP_Widget {
function List_Content() {
$widget_options = array('description' => 'This widget displays latest content with thumbnails from a selected category.', 'classname' => 'widget-listing');
parent::WP_Widget(false, 'Back My Book Latest Content', $widget_options);
}
function form($instance) {
// outputs the options form on admin
$instance = wp_parse_args((array) $instance, array('title' => __('', 'widget-listing'), 'cat_name' => 'Uncategorized', 'n_posts' => 5));
$title = esc_attr($instance['title']);
$cat_name = esc_attr($instance['cat_name']);
$n_posts = intval($instance['n_posts']);
$categories = &get_categories('type=post&orderby=name&hide_empty=0');
?>
'This widget displays featured content with thumbnails.', 'classname' => 'widget-listing');
parent::WP_Widget(false, 'Back My Book Featured Content', $widget_options);
}
function form($instance) {
// outputs the options form on admin
$instance = wp_parse_args((array) $instance, array('title' => __('', 'widget-listing'), 'cat_name' => 'bmb_widget_feature', 'n_posts' => 5));
$title = esc_attr($instance['title']);
$cat_name = esc_attr($instance['cat_name']);
$n_posts = intval($instance['n_posts']);
?>
|i', get_post_field( 'post_content', $args['post_id'] ), $matches );
/* If there is a match for the image, return its URL. */
if ( isset( $matches ) && $matches[1][0] ) {
return $matches[1][0];
}
}
/**
* Custom search form
*
* @since Back My Book 1.0
*/
function bmb_search_from() {
$field_value = __('To search, type and hit enter', 'backmybook');
?>
1 || $commentscount == 0) $commenttext = ' comments';
printf( __( 'by %3$s on %2$s %4$s', 'backmybook' ),
'meta-sep meta-prep-author',
sprintf( '%3$s',
get_permalink(),
esc_attr( get_the_time() ),
get_the_date()
),
sprintf( '%3$s',
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'View all posts by %s', 'backmybook' ), get_the_author() ),
get_the_author()
),
sprintf( '%3$s',
get_permalink(),
esc_attr__( 'View all comments', 'backmybook' ),
sprintf( esc_attr__( ' - %s', 'backmybook' ), $commentscount.$commenttext )
)
);
}
endif;
if ( ! function_exists( 'backmybook_posted_in' ) ) :
/**
* Prints HTML with meta information for the current post (category, tags and permalink).
*
* @since Back My Book 1.0
* @author Based WordPress Team Twenty Ten theme
*/
function backmybook_posted_in() {
// Retrieves tag list of current post, separated by commas.
$tag_list = get_the_tag_list( '', ', ' );
if ( $tag_list ) {
$posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the permalink.', 'backmybook' );
} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
$posted_in = __( 'This entry was posted in %1$s. Bookmark the permalink.', 'backmybook' );
} else {
$posted_in = __( 'Bookmark the permalink.', 'backmybook' );
}
// Prints the string, replacing the placeholders.
printf(
$posted_in,
get_the_category_list( ', ' ),
$tag_list,
get_permalink(),
the_title_attribute( 'echo=0' )
);
}
endif;
if ( ! function_exists( 'backmybook_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* @since Back My Book 1.0
* @author Based WordPress Team Twenty Ten theme
*/
function backmybook_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>