Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Voices That Matter

Web Design Reference Guide

Hosted by

Customizing WordPress 2.5.1: Using the Links and Archives Pages

Last updated Oct 17, 2003.

The Links and Archives template pages in the default theme contain coding to display links or archives, respectively, without you having to do anything at all.

Go to your blog's Dashboard and write a new page. From the Page Template drop-down list, choose Links or Archives as shown in Figure 1. Enter a title (such as Links or Archives), and then save and publish the page. You don't need to write anything in the body area for the page; in fact, if you do write anything, it will be ignored.

Figure 1

Figure 1 From the Page Template drop-down list, choose Links or Archives.

Refresh your blog and visit the page you just created. If you chose to create an archives page, you'll see a list of posts by month and another by category, as shown in Figure 2. If you created a links page, you'll see a list of links grouped by category, as shown in Figure 3.

Figure 2

Figure 2 An archives page with a list of posts by month and a second list of posts by category.

Figure 3

Figure 3 A links page with a list of links grouped by category.

Both default page templates provide adequate information, but your visitors would probably benefit from some closer attention to detail.

Modify the Archives Template

The Archives template is named archives.php. Open it with your text editor and you'll see the following template header:

Template Name: Archives

That's followed by code to get the header file, set up the page layout, and add a search box:

<?php get_header(); ?>
<div id="content" class="widecolumn">
<?php include (TEMPLATEPATH . '/searchform.php'); ?>

Below that is the crucial coding that creates the two lists of archives, by month and by subject (see Figure 4):

<h2>Archives by Month:</h2>
<?php wp_get_archives('type=monthly'); ?>
<h2>Archives by Subject:</h2>

<?php wp_list_categories(); ?>
Figure 4

Figure 4 The Archives page template sets up two lists: one for posts by month, and the other for a list of categories.

The WordPress Codex page for wp_get_archives explains all the possible ways you can change the time-based list. For example, you could replace the following line:

<?php wp_get_archives('type=monthly'); ?>

with this:

<?php wp_get_archives('type=weekly&show_post_count=1&limit=20'); ?>

The result would display a list of the last 20 (limit=20) weeks (weekly), with the number of posts for each week in parentheses at the end of the line (show_post_count=1), as shown in Figure 5. Remember to change the heading to match what the list displays.

Figure 5

Figure 5 A list of the last 20 weeks, with the number of posts for each week displayed in parentheses at the end of the line.

To list tags instead of categories, edit the code for the second list. Choose whether to display tags as a "cloud"—tags are grouped, and the font size reflects how often the tag has been used—or as a list down the page. You can find details of all the possibilities at the codex page for wp_tag_cloud.

Here's the code that would list tags down the page:

<h2>Archives by Tag:</h2>
<?php wp_tag_cloud('format=list'); ?>

Notice that I've changed the heading appropriately.

This code creates a tag cloud using the default cloud values (see Figure 6):

<h2>Tag cloud:</h2>
<?php wp_tag_cloud(''); ?>
Figure 6

Figure 6 The archive page now contains a couple of lists and a "cloud."

To give your blog's visitors the best experience, create several different types of archive pages—perhaps for categories, by month, by year, with tags—and let the visitor choose how he or she wants to view your posts.

Modify the Links Template

The Links template contains this coding:

<?php wp_list_bookmarks(); ?>


It produces a very raw and simple list of links, divided into categories, but you can do a lot to refine what's displayed. (Refer to the codex page for wp_list_bookmarks for a full breakdown of possibilities.) For example, this coding displays a simple, uncategorized list (categorize=0), with the "Bookmarks" heading removed (title_li=), and including the description (if available) for each link (show_description=1):


<?php wp_list_bookmarks('categorize=0&title_li=&show_description=1'); ?>

Figure 7 shows the result.

Figure 7

Figure 7 A simple, uncategorized list, with the "Bookmarks" heading removed, and including the description (if available) for each link.

With the following coding, I restrict the links displayed to those in category 32 or 33 (see Figure 8):

<?php wp_list_bookmarks('categorize=0&title_li=&show_description=1&category=32,33'); ?>
Figure 8

Figure 8 With restricted categories, fewer links are displayed.

The default Archives and Links templates provide adequate but unsophisticated listings. Previous articles showed you how to create a custom page template. Now you can add modifications to the default archives or links coding for fine control over your blog's templates.

Create customized archives and links page templates with tailored listings to give your visitors many more possibilities for finding your words of wisdom.