public
Created

A demonstration of how to add new widgetized areas to Thematic's Sample Child Theme

  • Download Gist
functions.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
<?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' );
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.