“Widgetizing Themes”的版本间的差异

跳转至: 导航搜索

2013年8月2日 (五) 04:23的版本


What is Widgetizing?

Widgetizing is a pseudo word that describes the process of implementing Widget's and Widget Area's into your Theme.

How to Register a Widget Area

The following should be added to your Theme's functions.php file:

 * Register our sidebars and widgetized areas.
function arphabet_widgets_init() {

	register_sidebar( array(
		'name' => 'Home right sidebar',
		'id' => 'home_right_1',
		'before_widget' => '<div>',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="rounded">',
		'after_title' => '</h2>',
	) );
add_action( 'widgets_init', 'arphabet_widgets_init' );

How to display a Widgets and Widget Areas

Please refer to the Widgets API to learn how to, programmatically, display Widgets and Widget Areas.

If you're not a programmer, you should refer to the WordPress Widgets page.

Tags: How do I display widgets?, How do I display a widget? How do I create a widget area?

I have a theme with more than one sidebar. How do I make them all dynamic?

Oh, that’s easy. Instead of register_sidebar() you should use register_sidebars(n) where n is the number of sidebars. Then place the appropriate number in the dynamic_sidebar() function, starting with 1. (There are several other ways to use these function.).

You can even give your sidebars names rather than numbers, which lets you maintain a different set of saved sidebars for each theme. But if you need to know so much about the plugin, why aren’t you reading the API?


模板:Sidebar Tags

Widgets API: is_active_sidebar, register_sidebars, register_sidebar, unregister_sidebar, is_dynamic_sidebar, dynamic_sidebar, register_sidebar_widget, unregister_sidebar_widget, wp_register_sidebar_widget, wp_unregister_sidebar_widget, wp_get_sidebars_widgets, wp_set_sidebars_widgets, is_active_widget, the_widget, register_widget, unregister_widget, register_widget_control, unregister_widget_control, wp_register_widget_control, wp_unregister_widget_control, wp_convert_widget_settings, wp_get_widget_defaults, wp_widget_description