WP Tutorial: How to make your theme Widget Ready

Wordpress has thousands of themes, of course, there are a considerable number of them do not support the widget tools to the sidebar, only through the code to modify. People can not help asking: How can I make the theme of our support for this widget? Can not find on google, or I have to write it ~

First of all, what are Widgets?

Almost half of the theme is support for widgets, and it is not a very difficult task. Widgets are small, you can add the wordpress control panel background to the sidebar (sidebar). Common widgets including the most recent articles, recent comments, categories and so on. WP2.7 you can in the Control Panel, click Appearance> widgets gadget settings to open the page.

How to achieve the theme of Widgets?

This process is very simple, perhaps too simple, wordpress theme will be so popular with Widgets.

Step One:

First of all, open the functions.php file, if the subject does not, please manually create, insert the following to ensure it is in labels.

if (function_exists ( ‘register_sidebar’))

register_sidebar (array (

‘Name’ => ’sidebar’,

‘before_widget’ => ‘<div>’,

‘After_widget’ => ‘</ div>’,

‘Before_title’ => ‘<h2>’,

‘After_title’ => ‘</ h2>’,

));

It is not difficult to find their own interpretation of a section of code, function is to create a widget-ready areas, and named for the sidebar, at the same time provides for Widgets which will run in the region, such as what appears in the Widgets, before which they appear in the following .

When using the Widget will be used when the following code:

<div>
<h2> Title Here ( “Recent Posts”, for example) </ h2>

Widget content is here, like a list of recent posts for example.

</ div>

So you can customize the widget’s border, title, etc., of course, now you can also use CSS to change the widget’s style, great bar.

Step Two:

The completion of earlier steps, save the file, and then open the sidebar.php, you show the widgets in place to paste the following code:

<? php if (! function_exists ( ‘dynamic_sidebar’) | |! dynamic_sidebar ( “sidebar”)):?>
<? php endif;?>

Make sure dynamic sidebar name in content is the same as you just set in function.php.

Learned to add widgets, you can add more than one sidebar widget, can add a header used to display ads, the footer shows the recent articles and reviews, of course, this is only recommended. Not always limited to the widget on the side, they really can be on any place you want.

If you have a better way,leave a here to share!

Popularity: 24% [?]