Widgets and widget areas are your friends when rolling out WordPress as a CMS. It is perhaps not as important for the small and static company Web sites primarily discussed so far, but rather for the larger ones. Take a look around online; there are numerous sites that push out mixed functionality, especially on their front pages, and display teaser images when it is suitable.
You can do this with widgets, and with the revamped widget API that WordPress 2.8 brought with it, this is now even easier to do. The most straightforward usage is to litter your site with widget areas wherever you may want to output something all of a sudden; just make sure that the area doesn’t output anything by default should you want it to be invisible (as in not containing anything) whenever you haven’t populated it with a widget. That being said, it is good to think your widget areas through, and put the areas where you need them, not where you think you may need them in two years time. After all, you will have redesigned the site by then anyway …
So you’ve got your widget areas in. Now, how to use them? Besides the obvious answer of drag-and-drop widgets on the Appearance → Themes page in WordPress admin, you'll need widgets that do what you need. The ones that ship with WordPress are simple and somewhat crude; the Pages widget (listing your Pages) won't even let you display just the Pages, it forces an h2 title out there, and this is a bad thing. You want control, so if you're moving down this route, be sure to look at other plugins that offer widget support. These days, a great many do, including ones that just list the Pages. (Seems I'm not the only one annoyed with that default h2 heading, after all.)
The most usable widget is by far the text widget. Why? Because it accepts HTML code, which means that putting text and images in it is a breeze. This is good, because if you want to show off that special promotion just below the menu in the header, you can just put the necessary HTML code in a text widget and drop it there for the duration of the campaign, and then just remove it, and the area will disappear. That is, if you kept it empty.
Why stop there? Why not just put empty widget areas where your various elements on the site could be? It will do the job, but you’ll have to cram them in wherever they will fit, and this will have to take the rest of the design and content into account. You will have to do that either way, of course, but there is an alternative. Replace parts of the content.
If you’re running an magazine-ish site, you may sometimes get the opportunity to roll out big so-called roadblocks, ads that take over a lot more of the site than just common banners and leaderboards. These things usually run for a shorter amount of time, and you get paid a lot for them, compared to ads. Or, take another approach: say you’re an Apple blogger and you want to cover the Apple WWDC or MacWorld in a timely manner, making sure that your readers won’t miss it. How? Plaster the site in promotional graphics of course!
Both these examples will work poorly (in most cases) if you just add stuffto widget areas positioned around the site’s normal elements. They will, however, work perfectly well if you replace parts of the site’s content, meaning any element really. This effect is pretty easy to get working, thanks to the fact that widget areas can come preloaded with content. This is a widget area called Teaser, and it should come preloaded with the content you want in that particular spot on a day-to-day basis:
<?php if ( !function_exists('Teaser') || !dynamic_sidebar() ) : ?>
[The normal content would go here. Links, headlines, whatever. . . ]
<?php endif; ?>
Just put it in there; it can be anything, really. A headline section, a poll, must-read lists, loops, links you name it. Anything. However, when you drop a widget in the Teaser widget area within the WordPress admin interface, the default content won’t show; it will be replaced with the widget you dropped. So dropping a text widget with your big fat promo image for the Apple event, or your new e-book, or whatever, will replace the original content. When you remove the image from the Teaser widget area, the default content will return by default.
Pretty nifty, huh? And actually pretty simple to maintain as well; if something goes wrong, you can just remove the widget you put there, and you’ll always revert to default. Another great use of widgets is navigational menus, which make sure users can add menu items themselves without having to rely on the theme designer.
Our website is not responsible for the information contained by this article. Webworldarticles.com is a free articles resource thus practically any visitor can submit an article. However if you notice any copyrighted material, please contact us and we will remove the article(s) in discussion right away.
This article was sent to us by:
Christian T. at
05132010
1. Creating Your Own Wordpress Template Tags
All articles in this directory are property of their respective authors. Additionally, read our Privacy Policy
© 2010 WebWorldarticles.com - All Rights Reserved.