888888.888888.88""Yb..dP"Yb..8888b..Yb..dP.88b.88....db....8b....d8.88..dP""b8..dP"Y8
88__...88__...88__dP.dP...Yb..8I..Yb.YbdP..88Yb88...dPYb...88b..d88.88.dP...`".`Ybo."
88""...88""...88"Yb..Yb...dP..8I..dY..8P...88.Y88..dP__Yb..88YbdP88.88.Yb......o.`Y8b
88.....888888.88..Yb..YbodP..8888Y"..dP....88..Y8.dP""""Yb.88.YY.88.88..YboodP.8bodP'


88b.88.888888.888888.Yb........dP.dP"Yb..88""Yb.88..dP
88Yb88.88__.....88....Yb..db..dP.dP...Yb.88__dP.88odP.
88.Y88.88"".....88.....YbdPYbdP..Yb...dP.88"Yb..88"Yb.
88..Y8.888888...88......YP..YP....YbodP..88..Yb.88..Yb

October 23, 2007

I have been several versions of Wordpress behind for a little while and, with this blog, have just caught up. My verdict? Widgets are pretty cool. Having said that it seems clear that the creators of widgets have missed a trick. Why stop with the sidebar?

Widgets give you control over the layout and contents of your sidebar, but there is no reason why you can’t use them to control other parts of your site. For example, in just ten minutes I was able to convert my home page to give me control over most of the layout. Now I am going to explain how.

Register a second sidebar

In the functions.php file, in my theme folder, I have now registered two sidebars. One is controlling my footer, and the other the content of my home page;

[php]
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'footer',
'before_widget' => '

',
'after_widget' => '

',
'before_title' => '

',
'after_title' => '

',
));
register_sidebar(array(
'name' => 'home page contents',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));

}

I’ve given then nice names so I recognise them in the admin console.

Create and register the home page content widget

Again in functions.php, I have produced a function to output the standard contents of the home page loop without any change. The example has a placeholder for simplicity:

[php]
function widget_home_page_content(){

?>

*** Loop Contents ****


}

I have then registered this function as a new widget

[php]
register_sidebar_widget('Home Page Content',widget_home_page_content);

Pretty simple so far right?

Convert your index to a sidebar

I have replaced the Wordpress loop in my index file, with a call to the second sidebar. My entire index file now looks like this:

[php]


I can now start to produce and use widgets to place content above and below the contents of my home page, without messing with the theme. I could even go further and break the loop into parts, giving even more control over the precise way posts are displayed, or make a single page theme, using widgets to control the layout.

I'm just wondering how far it is possible go using only widgets.

Post Image The Easy Peasy Way
Wp attachment functions?
26 comments
page 1065
Dont Mess With My Toot Toot
Wordpress custom content?
16 comments
page 599
Post Image The Easy Peasy Way
Inserting an image url in comments?
26 comments
page 1065
Using Your Own Url Shortener
String shortner?
4 comments
page 1190
Quick N Dirty Admin Login Screen
My admin login page?
no comment
page 128
Using Your Own Url Shortener
How to build a shortner link?
4 comments
page 1190
Post Image The Easy Peasy Way
Get post attacments?
26 comments
page 1065
Theming Habari Vs Wordpress
Habari vs wordpress?
13 comments
page 440
Are Child Themes The Best Option
Wp child themes?
15 comments
page 1262
Upload From Url
Upload to url?
6 comments
page 326
Silence Is Golden
Silence is golden wordpress?
3 comments
page 213
How To Add Sidebars To A Theme
Html hot add a side bar?
10 comments
page 1053
Fun With Sidebar Tabs Styling
Position of the tabs thematic?
2 comments
page 336
How To Add Sidebars To A Theme
How to add picture to the wordpress sidebar on sidebarphp?
10 comments
page 1053
Using Your Own Url Shortener
Short url?
4 comments
page 1190
Why I Ditched Disqus
Styling disqus widgets?
5 comments
page 1175
Wordpress 25 Exif Fields
Wordpress exif?
12 comments
page 230
Html 5 Gallery
Html 5 gallery?
6 comments
page 1305
Dont Mess With My Toot Toot
Fun with toots?
16 comments
page 599
Dont Mess With My Toot Toot
Fun with toots?
16 comments
page 599
Converting Wordpress Themes To Habari
Habari timthumb?
one comment
page 694
Wordpress 25 Exif Fields
Habari timthumb?
12 comments
page 230
Fun With Sidebar Tabs Styling
Tabs with html css on same page javascript?
2 comments
page 336
Using Your Own Url Shortener
How to have own url short?
4 comments
page 1190
Using Your Own Url Shortener
Run short url using htaccess?
4 comments
page 1190
Post Image The Easy Peasy Way
Insert conditional image php wp?
26 comments
page 1065
How To Add Sidebars To A Theme
Wordpress sidebar above main sidebars?
10 comments
page 1053
Html 5 Gallery
Html5 simple wordpress theme?
6 comments
page 1305
Dont Mess With My Toot Toot
New posttype not displayed wordpress?
16 comments
page 599
Quick N Dirty Replacement Text
Wpupdatepost object?
no comment
page 122
Updating Code Snippets Here
Fun wordpress plugin?
one comment
page 1338
Updating Code Snippets Here
Wordpress fun plugins?
one comment
page 1338
How To Add Sidebars To A Theme
Wp register sidebars?
10 comments
page 1053
  1 query every 2085 seconds, updated 1 seconds ago.
Saturday, 4am
 __
(__)
   `

 cakipin

thanks, it very good scrib

Thursday, 8pm
 __
(__)
   `

 Andrew Rickmann

Mak, I don't know the answer I'm afraid. It seems more likely that there is something up with the widget itself.

Thursday, 11am
 __
(__)
   `

 mak

hi please help. i have a theme with 3 columns ie: main page 2 sidebars side by side.

i have the cats, links in one and register and tags in the other.

But when i install a tweet widget the tweet widget is shown in my3 sidebar but everything else just disappears.

i wanted the widget to show under the rest of the items

please help

Monday, 2pm
 __
(__)
   `

 deshock.com » Blog Archive » We Need To Kill The Sidebar

[...] Developers: Check out Doing more with Widgets: Home Page Layout and Doing more with widgets: Changing Layouts for some fun tutorials on using WordPress [...]

Monday, 7am
 __
(__)
   `

 Andrew Rickmann

CarpetGuy,

You could do it as a plugin but this technique relies on changing the theme itself so if you changed the theme you are likely to lose most of it anyway.

Upgrading WordPress shouldn’t have an effect on this technique though as the only changes are to the theme files.

Sunday, 11pm
 __
(__)
   `

 CarpetGuy

I have one question, what happens when you upgrade? The way that I understand it, your additions, not done as a plug-in, will get over written when you upgrade. Might it be better to create a plugin instead of just changing code?

Tuesday, 9am
 __
(__)
   `

 wp-fun » Blog Archive » Doing more with widgets: Changing Layouts

[...] few weeks ago I showed how the home page contents could be moved into a widget to allow additional content to be added above and below it. That’s an interesting technique [...]

Sunday, 11pm
 __
(__)
   `

 Andrew Rickmann

Christopher, it is possible to install widgets as part of the functions.php file that sites in the template itself, so other than installing the template there isn’t really too much more you need to do.

Sunday, 8pm
 __
(__)
   `

 Christoph Voigt

I guess you could go pretty far with creating a theme that’s completely made out of widgets. However, the gain in flexibility comes with the price of increased administration.
If I’m not mistaken every widget has to be installed as a plugin. Really makeing use of a widget-based theme could easily create a dozen of widgets which will sooner or later clutter the plugins-page. Wouldn’t it be great if you could have a sort-of-wysiwyg editor for managing the entire theme?