wordpress: beyond the basics

Working with Widgets

Let's start by modifying the contents of your sidebar. A few years ago, this meant manually editing the sidebar.php template file in your theme. But the vast majority of themes developed in the past few years come with support for the newer WordPress "Widgets" system, which, in most cases, lets you control the contents of your sidebar via drag-and-drop.

If your theme has widget support, you'll see a Widgets section in the Dashboard sidebar, in the Appearance section:

Widgets1

If you're using an older, non-widgetized theme, you can either widgetize it yourself or be prepared to manage everything in your sidebar template with raw PHP code, by editing the sidebar.php template in your theme.

In the next section, Managing Links, we provide an example of modifying the sidebar manually rather than with widgets.

Your Widgets area should look something like this:

On the left you'll see a list of "Available Widgets," while on the right you'll see the currently available "Widget Areas." Most themes support just one widget - the "Primary Widget Area." If you open up the Primary Widget Area, you'll see its default set of widgets - for search, archives, categories and something called "meta." Try dragging one of these widgets up or down, then revisit your public site to see how your sidebar has changed. Cool, huh?

Notice that each of the widgets comes with a downward-facing arrow - click that to discover what things can be changed about the way that widget behaves. For example, click the arrow next to Recent Posts and change the Title field and the number of posts shown. Click Save, then check your site again.

Widgets3

And what if you want to remove a widget? Just drag it out of the Widget Area - the change is immediate. See the widget called "Meta?" That's the one that causes the Login link to appear in your site's sidebar. That's there by default to make things easy for new users, but it's unprofessional to include a Dashboard login link on your site (do you see one on the web site of your favorite newspaper?) Start by dragging that Meta widget out of the way.

Adding Widgets

Now let's try adding a new widget. Find the Pages widget and drag it into the sidebar. Click Save and check your site. Assuming you've actually created some pages (not posts) on your site, a list of them will now appear in your public sidebar. Notice that the widget also lets you control how your pages are sorted, and lets you exclude some pages so they don't appear in the sidebar.

How to find database IDs Certain features in WordPress need access to the database record IDs of certain pages, posts, or categories. The easiest way to find them is to visit the Page or Post or Category manager, click the record you're interested, and take a look at the URL. For example, if I wanted to exclude my About page in the step above, I would navigate to Pages in the Dashboard, click the link to the About page, then study the Dashboard URL:

Widgets6

See the parameter "post=2" in the URL? That means I'm looking at record #2.

Let's step it up a notch. Grab the "Text" widget from the Available Widgets section and into the Primary area. Once placed, enter some placeholder text and check your site. The nice thing about the Text widget is that it can also contain HTML and/or Javascript, which means it's a great way to add embed code from other sites (confusingly, other sites will often refer to their embeddable goodies as "widgets," so it's like you're putting a widget in a widget).

For example, try going to Twitter's Widgets page. Then click "For my website," then "Search widget." Type in "wordpress" as the search query, then click the Finish and Grab Code button. Copy the code they provide to the clipboard, then return to your Dashboard and paste into a Text widget. Click Save, and check your site - you've just embedded a real-time Twitter search query into a widget in your sidebar. How easy was that?!

Widgets4 Widgets5

Finding more widgets

In addition to the default set of widgets, your currently installed theme may provide additional ones. You also may end up with new widgets after installing certain plugins (not all plugins provide widgets, but some do). For example, notice the "NextGEN Slideshow" widgets in the screenshot above - those are present because the NextGEN plugin is installed on the site. Try searching the WordPress plugins directory for the word "widget" to find more.