* @copyright Copyright (c) 2012, Paul de Wouters
* @link http://pauldewouters.com
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
/** Load the core theme framework. */
require_once( trailingslashit( get_template_directory() ) . 'library/hybrid.php' );
new Hybrid();
/** Theme setup */
function pdw_spine_theme_setup() {
/** Custom thumbnail size */
add_image_size('featured', 637, 132, true);
/** Theme constants */
define ( 'PDW_SPINE_JS_URL', trailingslashit( get_template_directory_uri() . '/js' ) );
define ( 'PDW_SPINE_INC_DIR', trailingslashit( get_template_directory() . '/includes' ) );
define ( 'PDW_SPINE_DIR', dirname( __FILE__ ) );
define( 'PDW_SPINE_VERSION', '1.3.3' );
/** Template tags */
include_once PDW_SPINE_INC_DIR . 'template-tags.php';
/** Use Foundation nav bar markup for menus */
include_once PDW_SPINE_INC_DIR . 'navbar-walker.php';
/** Use Foundation makrup for galleries */
include_once PDW_SPINE_INC_DIR . 'gallery-shortcode.php';
/** Load main stylesheet */
add_action( 'wp_enqueue_scripts', 'pdw_spine_load_styles' );
/** Load the javascripts */
add_action( 'wp_enqueue_scripts', 'pdw_spine_load_scripts' );
/** Hybrid Core features */
/** Get action/filter hook prefix. */
$prefix = hybrid_get_prefix();
/** Add theme support for core framework features. */
add_theme_support( 'hybrid-core-menus', array( 'primary', 'secondary', 'subsidiary' ) );
add_theme_support( 'hybrid-core-sidebars', array( 'primary', 'subsidiary' ) );
add_theme_support( 'hybrid-core-widgets' );
add_theme_support( 'hybrid-core-shortcodes' );
/** Add theme settings */
add_theme_support( 'hybrid-core-theme-settings', array( 'about', 'footer' ) );
/** Include theme customizer options */
include_once 'includes/spine-customizer.php';
add_action( 'customize_register', 'pdw_spine_customize_register' );
add_theme_support( 'hybrid-core-template-hierarchy' );
/** Add theme support for framework extensions. */
//add_theme_support( 'post-stylesheets' );
add_theme_support( 'dev-stylesheet' );
//add_theme_support( 'loop-pagination' );
add_theme_support( 'get-the-image' );
add_theme_support( 'breadcrumb-trail' );
add_theme_support( 'cleaner-gallery' );
/** Add theme support for WordPress features. */
add_theme_support( 'automatic-feed-links' );
//add_theme_support( 'post-formats', array( 'image', 'gallery' ) );
add_theme_support( 'theme-layouts', array( '2c-l', '2c-r', '1c' ) );
/* Add support for WordPress custom background. */
add_theme_support(
'custom-background',
array(
'default-image' => trailingslashit( get_template_directory_uri() ) . 'backgrounds/satinweave.png',
'wp-head-callback' => 'pdw_spine_custom_background_callback'
)
);
/** Add support for WordPress custom header image. */
add_theme_support(
'custom-header',
array(
'wp-head-callback' => '__return_false',
'admin-head-callback' => '__return_false',
'header-text' => false,
'default-image' => 'remove-header',
'width' => 970,
'height' => 250
)
);
add_theme_support( 'featured-header' );
/** Set content width. */
hybrid_set_content_width( 637 );
//add_filter( 'wp_nav_menu_objects', 'pdw_spine_add_parent_class' );
add_filter( 'wp_nav_menu_objects', 'pdw_spine_add_active_class' );
add_filter( 'loop_pagination_args', 'pdw_spine_foundation_pagination' );
/* Register Spine widgets. */
add_action( 'widgets_init', 'pdw_spine_register_widgets' );
/** custom editor styles */
if ( is_admin() ) {
include( 'tinymce-kit/tinymce-kit.php' );
} // end if
//add_filter('post_thumbnail_html', 'pdw_spine_add_thumbnail_class',10, 3 );
add_filter( 'get_the_image', 'pdw_spine_add_featured_img_class', 10, 1 );
/** Register widget areas */
add_action('widgets_init', 'pdw_spine_register_sidebars', 11);
add_filter("{$prefix}_sidebar_defaults", 'spine_sidebar_defaults', 10, 2);
add_editor_style();
/** Jetpack feature */
add_theme_support( 'infinite-scroll', array(
'container' => 'hfeed',
'footer' => 'page',
) );
/* Disable primary sidebar widgets when layout is one column. */
add_filter( 'sidebars_widgets', 'pdw_spine_disable_sidebars' );
add_action( 'template_redirect', 'pdw_spine_one_column' );
// Add customizer styles to frontend
add_action( 'wp_head', 'pdw_spine_wp_head' );
}
add_action( 'after_setup_theme', 'pdw_spine_theme_setup' );
/**
* Registers Spine extra widget areas
*/
function pdw_spine_register_sidebars(){
/** Register front-page widget areas */
register_sidebar(
array(
'id' => 'banded-first-band',
'name' => __( 'Front Page First Band','spine' ),
'description' => __( 'This is the full width area at the top of the Front Page template.','spine' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => ''
)
);
register_sidebar(
array(
'id' => 'banded-second-band-1',
'name' => __( 'Front Page Second Band 1','spine' ),
'description' => __( 'This is the narrow area in the middle of the Front Page template.','spine' ),
'before_widget' => '',
'after_widget' => '
',
'before_title' => ''
)
);
register_sidebar(
array(
'id' => 'banded-second-band-2',
'name' => __( 'Front Page Second Band 2','spine' ),
'description' => __( 'This is the wider area in the middle of the Front Page template.','spine' ),
'before_widget' => '',
'after_widget' => '
',
'before_title' => ''
)
);
register_sidebar(
array(
'id' => 'banded-third-band-1',
'name' => __( 'Front Page Third Band 1','spine' ),
'description' => __( 'This is the wider area at the bottom of the Front Page template.','spine' ),
'before_widget' => '',
'after_widget' => '
',
'before_title' => ''
)
);
register_sidebar(
array(
'id' => 'banded-third-band-2',
'name' => __( 'Front Page Third Band 2','spine' ),
'description' => __( 'This is the narrow area at the bottom of the Front Page template.','spine' ),
'before_widget' => '',
'after_widget' => '
',
'before_title' => ''
)
);
}
function spine_sidebar_defaults($defaults, $sidebar){
if('subsidiary' == $sidebar){
/* Set up some default sidebar arguments. */
$spine = array(
'before_widget' => '',
'after_widget' => '
',
'before_title' => ''
);
} else{
/* Set up some default sidebar arguments. */
$spine = array(
'before_widget' => '',
'after_widget' => '
',
'before_title' => ''
);
}
array_merge($defaults,$spine);
return $spine;
}
/**
* Load the necessary CSS files
*/
function pdw_spine_load_styles() {
/* translators: If there are characters in your language that are not supported
by Open Sans, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'spine' ) ) {
$subsets = 'latin,latin-ext';
/* translators: To add an additional Open Sans character subset specific to your language, translate
this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. */
$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'spine' );
if ( 'cyrillic' == $subset )
$subsets .= ',cyrillic,cyrillic-ext';
elseif ( 'greek' == $subset )
$subsets .= ',greek,greek-ext';
elseif ( 'vietnamese' == $subset )
$subsets .= ',vietnamese';
$protocol = is_ssl() ? 'https' : 'http';
$query_args = array(
'family' => 'Open+Sans|Gentium+Basic',
'subset' => $subsets,
);
wp_enqueue_style( 'spine-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null );
}
/** This loads the main theme style.css */
wp_enqueue_style( 'main', get_stylesheet_uri() );
}
/**
* Load the necessary javascript files
*/
function pdw_spine_load_scripts() {
wp_enqueue_script( 'foundation-buttons', PDW_SPINE_JS_URL . 'jquery.foundation.buttons.js', array( 'jquery' ), PDW_SPINE_VERSION, true );
wp_enqueue_script( 'foundation-forms', PDW_SPINE_JS_URL . 'jquery.foundation.forms.js', array( 'jquery' ), PDW_SPINE_VERSION, true );
wp_enqueue_script( 'foundation-mq-toggle', PDW_SPINE_JS_URL . 'jquery.foundation.mediaQueryToggle.js', array( 'jquery' ), PDW_SPINE_VERSION, true );
wp_enqueue_script( 'foundation-navigation', PDW_SPINE_JS_URL . 'jquery.foundation.navigation.js', array( 'jquery' ), PDW_SPINE_VERSION, true );
wp_enqueue_script( 'foundation-topbar', PDW_SPINE_JS_URL . 'jquery.foundation.topbar.js', array( 'jquery' ), PDW_SPINE_VERSION, true );
wp_enqueue_script( 'foundation-tabs', PDW_SPINE_JS_URL . 'jquery.foundation.tabs.js', array( 'jquery' ), PDW_SPINE_VERSION, true );
//wp_enqueue_script( 'foundation-clearing', PDW_SPINE_JS_URL . 'jquery.foundation.clearing.js', array( 'jquery' ), PDW_SPINE_VERSION, true );
/** This is the main javascript file */
wp_enqueue_script( 'foundation-app', PDW_SPINE_JS_URL . 'app.js', array( 'jquery' ), PDW_SPINE_VERSION, true );
}
/**
* This is a fix for when a user sets a custom background color with no custom background image. What
* happens is the theme's background image hides the user-selected background color. If a user selects a
* background image, we'll just use the WordPress custom background callback.
*
* @since 0.1.0
* @link http://core.trac.wordpress.org/ticket/16919
*/
function pdw_spine_custom_background_callback() {
/* Get the background image. */
$image = get_background_image();
/* If there's an image, just call the normal WordPress callback. We won't do anything here. */
if ( ! empty( $image ) ) {
_custom_background_cb();
return;
}
/* Get the background color. */
$color = get_background_color();
/* If no background color, return. */
if ( empty( $color ) )
return;
/* Use 'background' instead of 'background-color'. */
$style = "background: #{$color};";
?>
menu_item_parent && $item->menu_item_parent == $menu_item_id ) {
return true;
}
}
return false;
}
/*function pdw_spine_add_parent_class( $items ) {
foreach ( $items as $item ) {
if ( pdw_spine_hasSub( $item->ID, $items ) ) {
$item->classes[] = 'has-flyout'; // all elements of field "classes" of a menu item get join together and render to class attribute of element in HTML
}
}
return $items;
}*/
function pdw_spine_add_active_class( $items ) {
foreach ( $items as $item ) {
$current_element_markers = array( 'current-menu-item', 'current-menu-parent', 'current-menu-ancestor' );
$current_class = array_intersect( $current_element_markers, $item->classes );
if ( ! empty( $current_class ) ) {
$item->classes[] = 'active'; // all elements of field "classes" of a menu item get join together and render to class attribute of element in HTML
}
}
return $items;
}
/** Customize loop pagination extension */
function pdw_spine_foundation_pagination( $args ) {
$args['before'] = '