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
- Unzip the plugin file into your /wp-content/plugins/ directory.
- Activate the plugin from the WordPress admin panel.
- 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).
- Set the $format and $catID variables to your liking (see descriptions of same below).
- If your site is in a language other than English, see the notes below.
- 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.
Localization
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
Formatting
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.
Support
Hopefully you won't experience any problems, but feel free to e-mail me if you do.