Want to add a Widget to your WordPress Blog?

 
One of my favorite features of Wordpress is the fact that it is so very customizable.  And it's so very easy to add in pieces that maintains a level of control over the site without having to manually change PHP or HTML files.  You can access it all from within the back end of Wordpress. You can customize these pieces and this extra control with Widgets.  I'm not going to go into to much detail here.  If you've been using Wordpress for very long you know what Widgets are. The key point here is that you can add a Widget section and then easily control, add, edit the content of that section from the admin of Wordpress under the Appearance section. Adding a Widget section is pretty straight forward even.  In your functions.php file, (or custom_functions.php for Thesis) you will just need to add something similar to the following line: register_sidebar(array('name'=>'New Widget', 'before_title'=>'<h3>', 'after_title'=>'</h3>')); The above is pretty simple right?  The "name" is set to whatever you want to call it.  And then you set the tags you want to wrap around the title. Make sure you use something descriptive for the name so you know what the widget is for. After adding this to the function file you should be able to visit the Widgets section under Appearance and start adding Widgets to it immediately. But we still have to decide where the widget is going to show up. So in your template page you'll need to add some code to set where the Widget shows up.  Usually you'll add some default text that will display if there are no Widgets for that section yet.  Here's an example, naturally you can style it how you want: <div id="footer-widgeted">
<div>
<ul id="footer-widget">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('New Widget') ) : ?>
<li>
<h3>Testing Widget Area</h3>
<p>This is an example of a widgeted area.</p>
</li>
<?php endif; ?>
</ul>
</div>
</div> That should do it.
In a future post I'll go into more detail and give some specific examples of adding widgets around a site.
.

Leave a Reply

Mobile | Standard