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

Screenshot

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:

2. Widget Logic

Screenshot

Sometimes you haw not poverty the aforementioned widgets to materialize the aforementioned artefact on every azygos tender of your blog. This is where the Widget Logic 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

Simply identify something kindred in your possess Widget Logic boxes, depending on where you poverty the widgets to display.

Sources:

3. Query Posts

Screenshot

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 Query Posts 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

Source:

4. 404 Templates

Screenshot

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

Screenshot

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

Related posts

You haw be fascinated in the mass attendant posts:

(al)


© Leland Fiegel for Smashing Magazine, 2009. |
Permalink |
54 comments |
Add to del.icio.us | Digg this | Stumble on StumbleUpon! | Tweet it! | Submit to Reddit | Forum Smashing Magazine



Post tags: widgets, wordpress


Share This Post

Please share your thoughts




You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CAPTCHA Image Audio Version
Reload Image

Search Blog

Recent Posts

Topics

Feed

Blogroll


Archives