If you’re a Wordpress Theme Author, or a website administrator using Wordpress as the Content Management System, then you already know how important a widgetized theme really is. Without adding in this functionality, you really limit the capabilities of not only your website and its content, but also your readers input and/or content.
So, how do I incorporate this Wordpress feature into MY template/theme, you’re asking? It could not be more simple.
Now, if you have no idea what Wordpress is, or if you’re an absolute beginner, I recommend reading a few docs over at http://www.wordpress.org, but if you’re ready for the skinny, here it is:
Go into your themes install directory, and look for a file named functions.php. If it doesn’t exist, create it using something simple such as notepad or pico. Basically any text editor that saves text as pure ANSI text. Markup is to be avoided, regardless if it’s supplied by the text editor or by you. Also, you’ll want to make sure you have no trailing spaces anywhere in the file. This will also produce errors.
Inside of functions.php, copy/paste the following code..
1 2 3 4 | <?php if ( function_exists('register_sidebar') ) register_sidebar(); ?> |
Note: Be very careful of any trailing spaces or blank lines you may have left anywhere in the file. This will render your functions file useless.
Your theme should have a sidebar.php, but if it does not, make one.
Inside of this file, copy/paste the following code..
1 2 3 4 | <ul> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?> <?php endif; ?> </ul> |
Save it, upload it or whatever you might need to do to make it go live (ready for viewing). Login to your Wordpress Admin Panel, go to “Design”, look for a link named “Widgets”, and simply drag and drop the widgets into your sidebar.
That’s it.