Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A demonstration of how to add new widgetized areas to Thematic's Sample Child Theme
<?php
/**
* Custom Child Theme Functions
*
* This file's parent directory can be moved to the wp-content/themes directory
* to allow this Child theme to be activated in the Appearance - Themes section of the WP-Admin.
*
* Included is a basic theme setup that will add support for custom header images and custom
* backgrounds. There are also a set of commented theme supports that can be uncommented if you need
* them for backwards compatibility. If you are starting a new theme, these legacy functionality can be deleted.
*
* More ideas can be found in the community documentation for Thematic
* @link http://docs.thematictheme.com
*
* @package ThematicSampleChildTheme
* @subpackage ThemeInit
*/
/**
* Define theme setup
*/
function childtheme_setup() {
/* The Following add_theme_support functions
* will enable legacy Thematic Features
* if uncommented.
*/
// add_theme_support( 'thematic_legacy_feedlinks' );
// add_theme_support( 'thematic_legacy_body_class' );
// add_theme_support( 'thematic_legacy_post_class' );
// add_theme_support( 'thematic_legacy_comment_form' );
// add_theme_support( 'thematic_legacy_comment_handling' );
/*
* Add support for custom background
*
* Allow users to specify a custom background image or color.
* Requires at least WordPress 3.4
*
* @link http://codex.wordpress.org/Custom_Backgrounds Custom Backgrounds
*/
add_theme_support( 'custom-background' );
/**
* Add support for custom headers
*
* Customize to match your child theme layout and style.
* Requires at least WordPress 3.4
*
* @link http://codex.wordpress.org/Custom_Headers Custom Headers
*/
add_theme_support( 'custom-header', array(
// Header image default
'default-image' => '',
// Header text display default
'header-text' => true,
// Header text color default
'default-text-color' => '000',
// Header image width (in pixels)
'width' => '940',
// Header image height (in pixels)
'height' => '235',
// Header image random rotation default
'random-default' => false,
// Template header style callback
'wp-head-callback' => 'childtheme_header_style',
// Admin header style callback
'admin-head-callback' => 'childtheme_admin_header_style'
)
);
}
add_action('thematic_child_init', 'childtheme_setup');
/**
* Custom Image Header Front-End Callback
*
* Defines the front-end style definitions for
* the custom image header.
* This style declaration will be output in the <head> of the
* document just before the closing </head> tag.
* Inline Syles and !important declarations
* can be used to override these styles.
*
* @link http://codex.wordpress.org/Function_Reference/get_header_image get_header_image()
* @link http://codex.wordpress.org/Function_Reference/get_header_textcolor get_header_textcolor()
*/
function childtheme_header_style() {
?>
<style type="text/css">
<?php
/* Declares the header image from the settings
* saved in WP-Admin > Appearance > Header
* as the background-image for div#branding.
*/
if ( get_header_image() && HEADER_IMAGE != get_header_image() ) {
?>
#branding {
background:url('<?php header_image(); ?>') no-repeat 0 100%;
margin-bottom:28px;
padding:44px 0 <?php echo HEADER_IMAGE_HEIGHT; ?>px 0; /* Bottom padding is the same height as the image */
overflow: visible;
}
}
<?php if ( 'blank' != get_header_textcolor() ) { ?>
#blog-title, #blog-title a {
color:#000;
}
#blog-description {
padding-bottom: 22px;
}
<?php
}
}
?>
<?php
/* This delcares text color for the Blog title and Description
* from the settings saved in WP-Admin > Appearance > Header\
* If not set the deafault color is set to #000
*/
if ( get_header_textcolor() ) {
?>
#blog-title, #blog-title a, #blog-description {
color:#<?php header_textcolor(); ?>;
}
<?php
}
/* Removes header text if the
* "Do not diplay header text…" setting is saved
* in WP-Admin > Appearance > Header
*/
if ( ! display_header_text() ) {
?>
#branding {
background-position: center bottom;
background-repeat: no-repeat;
margin-top: 32px;
}
#blog-title, #blog-title a, #blog-description {
display:none;
}
#branding {
height:<?php echo HEADER_IMAGE_HEIGHT; ?>px;
width:940px;
padding:0;
}
<?php
}
?>
</style>
<?php
}
/**
* Custom Image Header Admin Callback
*
* Callback to defines the admin (back-end) style
* definitions for the custom image header.
* Customize the css to match your theme defaults.
* The !important declarations override inline admin styles
* to better represent a WYSIWYG of the front-end styling
* that this child theme is currently designed to display.
*/
function childtheme_admin_header_style() {
?>
<style type="text/css">
#headimg {
background-position: left bottom;
background-repeat:no-repeat;
border:0 !important;
height:auto !important;
padding:0 0 <?php echo HEADER_IMAGE_HEIGHT + 22; /* change the added integer (22) to match your desired top padding */?>px 0;
margin:0 0 28px 0;
}
#headimg h1 {
font-family:Arial,sans-serif;
font-size:34px;
font-weight:bold;
line-height:40px;
margin:0;
}
#headimg a {
color: #000;
text-decoration: none;
}
#desc{
font-family: Georgia;
font-size: 13px;
font-style: italic;
}
</style>
<?php
}
function childtheme_add_widgetized_areas($widgetized_areas) {
$widgetized_areas ['Header'] = array('admin_menu_order' => 40,
'args' => array (
'name' => 'Header Aside',
'id' => 'header-widget-area',
'description' => 'The widget area displayed in the header.',
'before_widget' => thematic_before_widget(),
'after_widget' => thematic_after_widget(),
'before_title' => thematic_before_title(),
'after_title' => thematic_after_title(),
),
'action_hook' => 'thematic_header',
'function' => 'childtheme_header_widget_area',
'priority' => 10,
);
$widgetized_areas ['Below Header'] = array('admin_menu_order' => 60,
'args' => array (
'name' => 'Below Header Aside',
'id' => 'below-header-widget-area',
'description' => 'The widget area displayed below the header.',
'before_widget' => thematic_before_widget(),
'after_widget' => thematic_after_widget(),
'before_title' => thematic_before_title(),
'after_title' => thematic_after_title(),
),
'action_hook' => 'thematic_belowheader',
'function' => 'childtheme_below_header_widget_area',
'priority' => 10,
);
$widgetized_areas ['Crown'] = array('admin_menu_order' => 80,
'args' => array (
'name' => 'Crown Aside',
'id' => 'crown-widget-area',
'description' => 'The widget area displayed above the Primary Widgetized Area.',
'before_widget' => thematic_before_widget(),
'after_widget' => thematic_after_widget(),
'before_title' => thematic_before_title(),
'after_title' => thematic_after_title(),
),
'action_hook' => 'thematic_abovemainasides',
'function' => 'childtheme_crown_widget_area',
'priority' => 10,
);
return $widgetized_areas;
}
add_filter('thematic_widgetized_areas', 'childtheme_add_widgetized_areas' );
function childtheme_header_widget_area() {
if ( is_active_sidebar( 'header-widget-area' ) ) {
echo thematic_before_widget_area( 'header-widget-area' );
dynamic_sidebar( 'header-widget-area' );
echo thematic_after_widget_area( 'header-widget-area' );
}
}
function childtheme_below_header_widget_area() {
if ( is_active_sidebar( 'below-header-widget-area' ) ) {
echo thematic_before_widget_area( 'below-header-widget-area' );
dynamic_sidebar( 'below-header-widget-area' );
echo thematic_after_widget_area( 'below-header-widget-area' );
}
}
function childtheme_crown_widget_area() {
if ( is_active_sidebar( 'crown-widget-area' ) ) {
echo thematic_before_widget_area( 'crown-widget-area' );
dynamic_sidebar( 'crown-widget-area' );
echo thematic_after_widget_area( 'crown-widget-area' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.