Smart Archives for WordPress

Smart Archives is a rather simple WordPress plugin that will allow you to display your archives in a much "cleaner" format. You can see it in action here. You'll notice that everything on the page is hyperlinked (years, months, posts) and that all of the respective links are future-proofed.

Installation and Implementation

  1. Unzip the plugin file into your /wp-content/plugins/ directory.
  2. Activate the plugin from the WordPress admin panel.
  3. Set the $file variable to reference the absolute path1 to a file you'll use to hold your archives (when called, displayArchives() will display the contents of this file). Note that this needs to set in two locations (once in the smartArchives function, and once in the displayArchives function; both functions are in the smartarchives.php file).
  4. Set the $format and $catID variables to your liking (see descriptions of same below).
  5. If your site is in a language other than English, see the notes below.
  6. Call displayArchives() from wherever you want your archives to appear, as shown below.
<?php displayArchives(); ?>

"format" is one of three values: block, list, or both. "Block" produces the block of years and months,2 "list" generates a reverse chronological list of your posts, including links to monthly archives, and "both" gives you the block and the list.

"catID" is simply the number of the category you want to exclude. If you want to exclude more than one category, simply put a space between them (e.g., '14 20 1'). Keep in mind that the "block" doesn't exclude categories. If you do not modify these variables, the plugin will default to "both" and will exclude no categories.


To localize, you're going to want to modify the setlocale function from within the plugin. Unmodified, it should read setlocale(LC_ALL,WPLANG); you're going to want to change the WPLANG variable to reference your language and the encoding you want. For example, if you wanted the archives to display in Spanish, you would change the function call to read like this: setlocale(LC_ALL, 'es_ES'). If you'd like the archives to be in Spanish and UTF-8 encoded, you would change the function call to read like this: setlocale(LC_ALL,'es_ES.UTF-8').

Archives without using WordPress' Pages

Please see this post.

A Couple Notes About WordPress' Pages


Some people have been complaining that their formatting doesn't look like mine and that they are seeing linebreaks in weird places. I think the problem lies in the way the Pages feature formats the webpage. I don't use the Pages feature and so all of the linebreaks I stuck into the PHP code to make the HTML source "prettier," do just that. However, if you do use the Pages feature, you might want to remove the linebreaks ("\n") that are in the plugin code, because I think that Pages converts them to HTML (i.e., you end up with actual <p> and <br /> tags) and thus the page is ultimately rendered 'wrong.'

Using PHP

Apparently, if you want to run PHP code from within a WP Page you have to install a plugin to enable this "feature" (crazy, huh? I agree). That said, Exec-PHP does the trick.


Hopefully you won't experience any problems, but feel free to e-mail me if you do.

  1. This is the path on your web server, not a URI (i.e., not The directory where you store all of your WordPress files is probably sufficient.

    If you have access to a shell on your web server, you can get the absolute path by going to the directory where you would like to keep the archives file and issuing the "pwd" command.

    If you do not have shell access, you can get the absolute path simply by creating a PHP file with the following code: <?php echo getcwd(); ?>. Use your FTP client to place that file in the directory where you want your archives file to reside, and then access the file from your browser (e.g., — it should spit out the path you need.

    You'll obviously want to append to this path the name of the file you want to use for the archives (e.g., if the PHP file or the "pwd" command spits back /path/to/this/directory/, then the path you're going to want to use for the $file variable will be something like, /path/to/this/directory/archives.txt.   

  2. Empty months are included (to balance the block), but are not hyperlinked. If you'd like to change the text color of these months (as I do on my archives page), you simply need to define a CSS class called "emptymonth" in your stylesheet.