Going down? the dark knight, watchmen style - http://tinyurl.com/94x2v2 35 mins ago
Tags: , ,

As I’ve continued to become more advanced with Wordpress, I’ve become increasingly acquainted with the notion that using it as a CMS ends up being one giant hack. I’ve had learning Expression Engine and Django on my to-do list for some time, but at the end of the day, it usually ends up being easier to just franken-rig it into place using my faithful old WP installation.

One of the first things a blogger typically does after installing wp is to change the default link structure from something like

http://yoursite.com/?p=16

which means absolutely nothing to the visitor, into something like

http://yoursite.com/year/month/day/post-name

There are several reasons one should do this, but the two main ones I identify with are that it makes your URL’s guessable, and it also helps with your Google rank. For the most part, this involves adjusting your wp-admin control panel under “options” and having it alter your .htaccess file in the root of your server so that mod rewrite is brought into play.

One of the biggest hurdles I had to overcome in order to get my portfolio into place using the database was that I didn’t want my portfolio entries to look like just another blog post. I knew that I wanted “blog” posts to show up under elihorne.com/journal/post-name, and portfolio posts to arrive under elihorne.com/portfolio/post-name. Behind the scenes, I have two main categories, journal and portfolio. When I go to update the site, I check off the appropriate category, and wordpress takes care of the heavy lifting.

By setting my permalink structure my custom “/%category%/%postname%/“, the system will only show exactly what I want it to. If you aren’t already familiar with the Wordpress Codex, you should go acquaint yourself because it can tell you how to do pretty much anything*.

elihorne.com - permalink magic
Click the picture for a larger view

*At this point, everything should work, only it didn’t. Any Twitter people who follow my twitter feed might remember that I documented this problem with various expletive ridden posts. The problem is that wordpress inserts by default http://yoursite.com/category/your-category-name/, and all my posts were getting lost in translation. Inside your wp-includes folder is a file called “rewrite.php”. This is where all the instructions live on how to interpret a permalink. Searching for “category_base” reveals that WP is hardcoded to insert “category/” before your link structure. This was easily removed, After making this adjustment, all my links resulted in “error 404: not found.”

MY SOLUTION
CAVEAT: I consider this a “hack.” I altered core wordpress files to make my blog jump through my hoops. Following these instructions is done at your own risk, and may result in your blog, well, not blogging.*****

I stumbled upon a link to a german blog (can’t find the link now) that described a secondary change to rewrite.php. After removing “category/” from category_base, run a search for “// Put them together” (without the quotes).

There you will see a hierarchical breakdown of the rewrite rules. What is important to notice here is that $category_rewrite appears before author_rewrite, and subsequently, date_rewrite and post_rewrite. Simply moving $category_rewrite to the head of the link (i.e. search>author>date>post>category instead of search>category>author>date>post) made all my problems dissapear.

Hope this helps people. remember: this is a hack, and unless you know what you are doing, may result in your blog breaking. I am not responsible for the sky falling on your head, even though it works fine for me. It should be noted that my pagination doesn’t work, but thats just because I haven’t had the chance to tweak it. I believe it is unrelated to my changes, and the result of some other things I’ve adjust behind the scenes.

Instructions and documentation on my search/discovery can be found in the Wordpress Support forums in this thread.

Leave a Reply