刚接触WordPress Thematic框架,不太熟悉,干啥都得到处找代码,今天要处理一下Sidebar,找了一段代码,赶快记下来,免得忘记。

移除Sidebar

下面这段代码会移除Thematic默认的Sidebar:Primary Aside

function remove_primary_aside($content) {
	unset($content['Primary Aside']);
	return $content;
}
add_filter('thematic_widgetized_areas', 'remove_primary_aside');

添加一个新的Sidebar

能移除就得能添加,添加的代码似乎多了点

function add_header_aside($content) {
	$content['Header Aside'] = array(
		'args' => array (
			'name' => 'Header Aside',
			'id' => 'header-aside',
			'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'	=> 'thematic_header_aside',
		'priority'	=> 8,
	);
	return $content;
}
add_filter('thematic_widgetized_areas', 'add_header_aside');
 
// And this is our new function that displays the widgetized area
function thematic_header_aside() {
	if (is_sidebar_active('header-aside')) {
		echo thematic_before_widget_area('header-aside');
		dynamic_sidebar('header-aside');
		echo thematic_after_widget_area('header-aside');
	}
}

然后在sidebar.php或者loop外部用thematic_header_aside()函数就可以调用这个新的header sidebar了