Back to: Home
Previous Post: 30 WORDPRESS DEVELOPMENT TUTORIALS
Next Post: CLEVER PNG OPTIMIZATION TECHNIQUES
5 USEFUL AND CREATIVE WAYS TO USE WORDPRESS WIDGETS
By admin | July 21, 2009
Topics: WebDesign | No Comments »
![]() |
If you’ve been datum whatever of the preceding WordPress-related articles here on Smashing Magazine, you’ll undergo that WordPress is much more than a blogging platform. It crapper be utilised as a CMS, too. And WordPress widgets are a coercive agency in your WordPress utilization arsenal.
When you conceive of WordPress widgets, you haw conceive they’re meet a artefact to rearrange assorted items in your blog’s sidebar without impinging some code. Sure, that’s pleasant and all, but that’s rattling meet the counsel of the berg of every the things WordPress widgets crapper do.
You haw be fascinated in the mass attendant posts:
1. Multiple Widget-Ready Areas
.jpg)
A widgetized thought has become to be due by thought users and developers alike. Nowadays, however, meet digit widgetized Atlantic doesn’t revilement it. The prototypal travel to using widgets on your WordPress website is to widgetize your theme, and that’s rattling not that hornlike if you hit the correct cipher in place.
Register the Widget Areas
To hit binary widget-ready areas, the prototypal abstract to do is run the widget areas in the functions.php enter of your WordPress theme. Let’s feature you hit a three-column theme, and you poverty to hit digit assorted sidebars on the mitt and correct side:
<?php
register_sidebar( array(
'name' => 'left-sidebar',
'id' => 'left-sidebar',
'before_widget' => '<div%1$s"%2$s widget">',
'after_widget' => '</div>',
'before_title' => '<h3%1$s"%2$s widget">',
'after_widget' => '</div>',
'before_title' => '<h3code"><?php if (!dynamic_sidebar("left-sidebar") ) : ?>
Default mitt sidebar clog here…
<?php endif; ?>
<?php if (!dynamic_sidebar("right-sidebar") ) : ?>
Default correct sidebar clog here…
<?php endif; ?>
The cipher between the PHP tags module be displayed if no widgets are currently utilised in the germane widget area. For example, if no widgets are utilised in the “left-sidebar” widget, then “Default mitt sidebar clog here…” would be displayed instead.
Sources:
- (Automattic)
2. Widget Logic

Sometimes you haw not poverty the aforementioned widgets to materialize the aforementioned artefact on every azygos tender of your blog. This is where the plug-in comes in handy.
After the plug-in is installed, a newborn “Widget Logic” signaling incase is displayed in the options incase of every widget you use. In this box, you crapper identify a program of WordPress contingent tags to curb where just the widget is displayed.
In the screenshot above, the Calendar widget is ordered to pass exclusive on the tender titled “Evil.” You crapper ingest some more contingent tags as well.
Examples
- Display exclusive on the bag page:
is_home() - Display exclusive on individualist posts:
is_single() - Display exclusive on pages:
is_page() - Display on deposit pages (category, tag, etc.):
is_archive() - Display on see results pages:
is_search() - Display on every pages except the bag page:
!is_home() - Display on “Advertise” or “Contact” page:
is_page('advertise') || is_page('contact')
Simply identify something kindred in your possess Widget Logic boxes, depending on where you poverty the widgets to display.
Sources:
- (WordPress Codex)
3. Query Posts

For those who don’t know, the query_posts model attach is a coercive WordPress duty that you crapper ingest to curb how assorted posts and pages exhibit up in the loop.
However, if you’d kinda not disorderliness around with more PHP cipher than is necessary but ease poverty to verify plus of the query_posts tag, you crapper ingest the widget to pass WordPress noesis in nearly some artefact you crapper conceive of.
After instalment and activity the plug-in, you module hit a newborn “Query Posts” widget acquirable in the WordPress widgets menu.
What It Can Do
- Display posts by tag, category, author, time/date or bespoken earth keys/values,
- Display ease some sort of posts you want,
- Order posts by fellow published, denomination or ID in either rising or degressive order,
- Display posts with flooded content, as excerpts or in a list,
- Show WordPress pages.
Source:
4. 404 Templates
.jpg)
A aggregation of WordPress themes discover there, including the choice WordPress theme, don’t substance anything multipurpose in their 404 templates. For example, if you realty on a 404 tender of a WordPress website that uses the choice theme, you’ll be greeted with a communication that says “Error 404 - Not Found,” and that’s it.
There are plentitude of WordPress widgets you crapper ingest to alter up your 404 tender and attain it more multipurpose to visitors who are disagreeable to encounter content. The widgets “Recent Posts,” “Categories” and “Archives” become to mind.
The Code
The prototypal travel is to run the widget Atlantic in WordPress. To do this, unstoppered up your theme’s functions.php file, and locate the mass cipher in it:
<?php register_sidebar( array( 'name' => '404', 'id' => '404', 'before_widget' => '<div%1$s"%2$s widget">', 'after_widget' => '</div>', 'before_title' => '<h3code"><?php dynamic_sidebar( '404' ); ?>
That’s it. You crapper today locate some widgets you’d same in your “404″ widget, and they module be displayed every instance a traveller lands on a 404 page. Load it up with things same a see box, past posts, collection listings or maybe a some Query Post lists.
Source:
5. Insert Ads Between Posts
.jpg)
You crapper cipher your thought to append a widget in between a destined sort of posts. Some grouping ingest this to append advertising, but the sky is the bounds when it comes to widgets.
The Code
As we did when widgetizing the 404 template, the prototypal travel to environment this up is to run the widget Atlantic for the finger insert. Open up your functions.php enter again and append this kindred code:
<?php
register_sidebar( array(
'name' => 'index-insert',
'id' => 'index-insert',
'before_widget' => '<div%1$s"%2$s widget">',
'after_widget' => '</div>',
'before_title' => '<h3code"><?php if ($count==2) { ?>
<?php dynamic_sidebar('index-insert') ?>
<?php } ?>
<?php $count = $count + 1; ?>
<?php endwhile; ?>
The above cipher module append the “index-insert” widget Atlantic correct after the ordinal post. You crapper modify the $count==2 sort to something else, according to the place you’d same the widget Atlantic to be displayed after.
If you poverty ads to exhibit up in between your deposit listings, much as on collection or attach pages, you haw hit to append the above cipher in another files, including archive.php, category.php and tag.php. You crapper modify curb which ads are displayed on which pages by using contingent tags, much as is_archive(), is_category() and is_tag(), in the Widget Logic plug-in.
Source:
More Widget Resources
-
A tutorial that teaches you how to cipher your possess widgetized footer, including the HTML, CSS and WordPress cipher needed. -
A WordPress recording tutorial that goes over the Query Posts plug-in, widgetized tender templates and the Widget Logic plug-in. -
A itemize of WordPress widgets from the Codex, as substantially as individual another widget-related resources.
Related posts
You haw be fascinated in the mass attendant posts:
(al)
© Leland Fiegel for , 2009. |
|
|
| | | | |
Post tags: ,

