Some simple notes about widgetizing a theme
-
I followed the advice in https://codex.www.ads-software.com/Widgetizing_Themes but found the text a little confusing. So I thought I would write some notes about what I found out when I made a theme widget aware.
I am using a customised version of theme neo-sapien version 0.6 which was not widget aware. It did not have a functions.php file in its theme folder (that’s /var/www/wordpress/wp-content/themes/neo-sapien-dev on my computer), so I copied the one from the Classic theme.
Amongst other things, that contains the code
if ( function_exists(‘register_sidebar’) )
register_sidebar(array(
‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ”,
‘before_title’ => ”,
‘after_title’ => ”,
));In wp-admin -> Appearance -> Widgets, widgets are now enabled, so I added a text widget to the sidebar, put some stuff in it and saved it.
(As expected, nothing yet appears on the site.)
I added
<?php if ( !function_exists(‘dynamic_sidebar’)
|| !dynamic_sidebar() ) : ?>
<?php endif; ?>into my php code and saved it.
(On refreshing the web page of the site, the widget appears.)
It does not matter where you put it, widget(s) appear at that place.
If you put it in more than once, the same widget(s) appear more than once.
You can omit the static alternative to the dynamic widgets.
If you want more than one widget area, edit functions.php to use the simpler version described in the codex, e.g.:
if ( function_exists(‘register_sidebars’) )
register_sidebars(2);If you put the same call to e.g. dynamic_sidebar(1) more than once, the same widget(s) appear more than once.
More usual is to have dynamic_sidebar(1) in one place and dynamic_sidebar(2) in another.
- The topic ‘Some simple notes about widgetizing a theme’ is closed to new replies.