arrow-left arrow-right brightness-2 chevron-left chevron-right facebook-box facebook loader magnify menu-down rss-box star twitter-box twitter white-balance-sunny window-close
Archives without using WordPress' Pages
1 min read

Archives without using WordPress' Pages

A fair majority of the Smart Archives e-mail I field is concerned with how to actually create the /archives/ directory structure without using WordPress’Pages. I thought about just putting the solution on the project page, but I think this tip will help others with similar problems (unrelated to WordPress) and so I’m posting it here on the weblog.

I’m working off the assumption that you want the same URI as my archives page (i.e., foo.com/archives/). The first thing you are going to want to do is create the /archives directory off your root. After you’ve created this directory, place your PHP file (the one with the Smart Archives function call) within this directory. Make sure that this PHP file has the following code at the top:

<?php require('/path/to/wp-blog-header.php'); ?>

Once the PHP file is placed in the /archives directory, you’re going to need to add the following line to your root .htaccess file:

RewriteRule ^archives/ archives/index.php [QSA]

It’s probably self-explanatory, but this rule redirects any page request that falls under the /archives directory and points it to the index.php file sitting in /archives. This line must go after whatever htaccess rules that WordPress, or you yourself, have already put in your .htaccess file that redirect browsers pointed to pages within the /archives directory.¹

That’s all there is to it.


FOOTNOTES
  1. The idea here is that you want to make sure that other rules concerning /archives are processed before this rule; if they weren’t, then any attempt to reach a non-index archive page (i.e., the archive of an individual post) would result in the user being redirected to your /archives/index.php file.
You've successfully subscribed to Justin Blanton.
Success! Your account is fully activated, you now have access to all content.