Ferodynamics Network

popular: profile privacy, mobile privacy

December 6, 2008

Following on from my post about Widget Management Concepts, I have produced a new plugin with the aim of making it super easy to include widgets within themes without needing to be concerned with writing plugins, or code in functions.php.

Installation

To install the plugin just download it and activate it. It has no options.

Creating Theme Widgets

Creating a theme widget really is very easy. Here is a step by step process.

Step 1

Create a new PHP file in the theme and call it {something}.widget.php.

Step 2

Add a PHP comment at the top of the file to indicate the name and description of the widget. Like this:

[php]
/*
Widget Name: 3 Random Posts
Widget Description: Outputs 3 random posts in a list
*/
?>

Step 3

Add the code you want for your widget. In this example I am adding code to output three posts at random:

[php]




Note that this code is identical to the code you would insert into a theme file to do this manually. There is nothing special about this code that needs to be changed to make it a widget.

Step 4

Assign the widget to sidebar.

workingwidget

On the left of the image is the output (there is only one post because it is a fresh installation) on the right the widget added to the sidebar.

Download

You can download the plugin from WordPress extend.

The Potential

I think that making it this easy to create, and more importantly understand, the widgets included with a theme opens up a lot of possibilities. For example, with this it would be easy to use a sidebar and widgets to offer different layouts for a featured post on the home page.

If you have any suggestions for improvements to the plugin itself, or ideas about how it can be used, let me know.

Html 5 Gallery
6 comments
page 1305
Wordpress Chat
one comment
page 1308
Html 5 Gallery
6 comments
page 1305
Silence Is Golden
3 comments
page 213
Questions About Habari For Wordpress Users
6 comments
page 424
Theming Habari Vs Wordpress
13 comments
page 440
My Experience Of Flexx
4 comments
page 1026
Plugin Update Fun With Photo Data 2
one comment
page 815
Post Image The Easy Peasy Way
26 comments
page 1065
Categories Vs Tags Either Neither Or Both
12 comments
page 7
Gaining Benefits From Plugins
8 comments
page 1167
Fun With Theme Widgets
24 comments
page 867
Beware Wp Cache
8 comments
page 1310
Six Million Ways To Die Choose One
14 comments
page 1128
Post Image The Easy Peasy Way
26 comments
page 1065
Post Image The Easy Peasy Way
26 comments
page 1065
Wordpress Chat
one comment
page 1308
Post Image The Easy Peasy Way
26 comments
page 1065
Wordpress Chat
one comment
page 1308
Beware Wp Cache
8 comments
page 1310
Wp Polls Reviewed
one comment
page 58
Fun With Photo Data
12 comments
page 330
Html 5 Gallery
6 comments
page 1305
Fun With Sidebar Tabs Styling
2 comments
page 336
Using Your Own Url Shortener
4 comments
page 1190
Html 5 Gallery
6 comments
page 1305
My Experience Of Flexx
4 comments
page 1026
Fun With Sidebar Tabs
193 comments
page 57
Html 5 Gallery
6 comments
page 1305
Fun With Plugins
27 comments
page 14
Wordpress 25 Exif Fields
12 comments
page 230
Html 5 Gallery
6 comments
page 1305
Html 5 Gallery
6 comments
page 1305
Beware Wp Cache
8 comments
page 1310
Html 5 Gallery
6 comments
page 1305
Quick N Dirty Replacement Text
no comment
page 122
Theming Habari Vs Wordpress
13 comments
page 440
  updated 1 seconds ago
Sunday, 10am
Andrew Rickmann

Can you paste the entire error in?

Sunday, 8am
Andy

I'm getting the Parse error: syntax error, unexpected T_STRING, expecting '(' in error too.

Thursday, 7pm
Andrew Rickmann

I wouldn't recommend bundling plugins in with themes. Technically it is fine, but if the plugin is updated to cope with a new version of WordPress anyone using the theme would be stuck.

Thursday, 7pm
Bret Holstein

I completely agree with your rationale for this plugin. It would make modifying themes and reusing components in different themes a whole lot easier if the theme widgets could be isolated into their own files.

Is there any reason why this couldn't be adapted to the functions.php file that comes with a theme? I'm not quite sure how it might be accomplished in practice but I would love to use the features of the plugin without requiring the users of my theme to load the plugin.

Any pointers on where to begin?

Monday, 1pm
Golden Retriever Puppies

Thanks for a great post, the plugin sounds of utility, I would want to give this a try.
Thanks for the step by step instruction would make it easy to get along on a fly..

Saturday, 5pm
free satellite

Development of digital technologies occurs prompt rates. Does not lag behind progress and digital TV. Speaking about digital TV, we first of all mean satellite TV. The digital satellite TV becomes more and more accessible to simple users. The market paid satellite tv also is not necessary on a place. The new digital standard of TV of high clearness HDTV actively develops and takes root. The satellite TV becomes more and more directed on the spectator. Besides digital quality of the image, advantage of satellite systems also is also the extensive cover zone of the companion.

Wednesday, 8pm
pregnancy symptoms

I wish to wish all pregnant women of good mood, easy pregnancy and natural sorts! Good luck also are happy! Give birth easily and independently! Let not doctors give birth for you, and you! Also adjust itself on chest feeding of the kid! Read the necessary information! Be, lovely pregnant mums and expecting posterities of the daddy, are healthy and wise!

Saturday, 1am
Andrew Rickmann

Kevin, that sounds like you are running on PHP 4. I haven't included PHP4 support in this plugin; although, I don't think there is anything in it that wouldn't run on PHP4 except the constructor itself.

If you amend public function __construct(){

to read

function fw_theme_plugins() {

then that might work. I haven't tested it though.

Saturday, 1am
Kevin Sandridge

Hi – any reason this plugin might not work with WP 2.7? Getting the following error code when I try to activate it:

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /mnt/local/home/fmblogger/floridamortgageblogger.com/wp-content/plugins/fun-with-theme-widgets/fun_with_theme_widgets.php on line 31

Friday, 11am
My experience of Flexx – WP FUN

[...] type of post (journal entry or photos) and as such had some extra code to output that. I used my Fun with Theme Widgets plugin to convert this to a widget and then attached it to the [...]

Saturday, 1am
Jazzthedog

Great plugin!

It's a great way of collecting your favorite snippets of code you would normally use and all of a sudden..it's a widget!

A couple of minor issues.

1. I tested this out within a 'child' theme and I had to copy the php file to the 'parent' theme to get it to show up in the GUI.

2. After adding it to the widget section , I could not click on edit to remove it. I had to deactivate the plug.

I can imagine after adding many of these widgets, with the current GUI implementation of widgets in WP 2.7 will become quite painful. Perhaps WP 2.8 will make it better.

Wednesday, 12pm
WordPress Plugin Releases for 12/08 | BlogBroker24-7

[...] Fun with Theme Widgets [...]

Tuesday, 9pm
Bloodhound Scenius in a Widget | Real Estate Blog Lab

[...] I found a new plugin for building Theme widgets called Fun With Theme Widgets [...]

Tuesday, 9am
leg med nye medier. Eller noget.

[...] Fun with Theme Widgets – WP FUN (tags: wordpress plugin widget) [...]

Monday, 7pm
Andrew Rickmann

Monika,

Trackbacks are a nice idea, but in practice I got so much spam and so many one line links that it wasn't worth it.

I am happy for you to add your link in any comments here, especially when you are promoting something I have done :-)