Archive for the ‘Open Source Software’ Category

WordPress Tip: Adding Custom Menus to a Theme

If you're using WordPress 3.0 or above (which, if you're using WordPress, you really should be), you have the option of adding custom menus to your theme without extra plugins.

In the past, this was managed via plugins such as "Page Links To" and "Exclude Pages." Now, this can all be managed within the WordPress admin console and in your theme, with a decent amount of customization.

In this tutorial, I'm assuming you know the basics of PHP (enough to create your own theme, at least).

To tell WordPress that this theme supports menus, add the following code to your theme's functions.php file:

// I want to add a header and footer
register_nav_menus( array(
        'header' => 'Top Navigation',
        'footer' => 'Top Navigation',
));

To use a menu in your theme files, you will need to add a line similar to what's shown here. I added this in my header.php file for the top navigation, and added a similar line to footer.php:

wp_nav_menu('sort_column=menu_order&menu_class=header-nav&menu=header');

There are many more options available for how your menu is displayed; see the WordPress Codex page for wp_nav_menu.

To create your new menus in WordPress, go to the admin console, click Appearances > Menus. This screen is fairly self-explanatory. I was able to replace three plugins and some custom header/footer code using only this method, in about 10 minutes (including research on wp_nav_menu).

For even more hardcore customization using custom walkers (a feature described in the Codex), check out Christian Budschedl's excellent post, Improve Your WordPress Navigation Output.

Happy blogging!

Movable Type Installation on Windows Server 2003

Wow, what a pain in the ass. I'm glad I didn't personally pay for this software. I thought this was yet another PHP content management system.

Nope, it's Perl.

To hopefully save someone from searching all over the web and back, here are the problems I encountered while installing. This guide assumes a semi-proficient knowledge of IIS configuration.

Install ActivePerl

First off, make sure you install ActiveState's ActivePerl on your server. Manually configuring Perl is not something I'd care to dive into. If that's your bag, go to CPAN (and why the hell are you reading this guide?).

Using the IIS Manager, navigate to your website and choose "Properties". Under the "Home Directory" tab, click the "Configuration" button.

In the Application Configuration window, click the "Add" button.

Use the following values in the Extension Mapping dialog:

Executable: C:\Perl\bin\perl.exe "%s" %s
Extension: .cgi
Verbs: Check "Limit to:" and enter GET,HEAD,POST
Uncheck the box labeled "Verify that file exists" (this will speed execution on scripts)

Next, select the "Web Service Extensions" item on the left of the IIS Manager (at the same level as "Web Sites"). Select "Perl CGI Extension" and click the "Allow" button.

I already had PHP installed on this server, so I'm skipping that step for this guide. PHP is far less tricky to install, anyway, and there are extensive guides for this already.

Fix Shoddy Installation Procedures

When navigating to my Movable Type directory, I immediately encountered the error "CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers."

Bad CGI application, bad! Smack it on the nose with a rolled up magazine!

First off, you should run the mt-check.cgi script to make sure everything's on the up-and-up. If the script runs successfully, you've successfully installed and configured ActivePerl. Yay, you're halfway (yes, halfway) there!

Near the top of this page, you should see the following:

Current working directory: [path]
MT home directory: [different path]

The MT Knowledge Base says to download this modified Bootstrap.pm file, and replace it with the version on your server. I honestly don't know what's different about it, or why they couldn't include it with the installation, or even if it does anything different. Mindlessly obey.

The same page also advises to "Create a new "virtual directory" under IIS which points to the physical directory where the Movable Type CGI files are located (i.e., the "MT home directory" mt-check.cgi reports)" That explanation is freaking stupid. What it should tell you is "Do not install MovableType directly into the folder you wish to present to the world." As in, I moved the entire thing to /cgi-bin/ and created a virtual folder named "blog" under the root folder pointing to /cgi-bin/. Your CGIPath variable in mt-config.cgi should match your virtual folder name (like http://www.example.com/blog/).

Install MySQL Driver

Oops, now navigating to the blog URL results in an error saying that the MySQL driver is missing (sharp readers will notice this was missing in mt-check.cgi as well, I did not). On your server, run the ActiveState Perl Package Manager, which should be in your Start menu. If you scan through all packages, you'll notice a DBD-mysqlPP module. This will not work, as far as I know. You need to add another repository source to get the actual module you need.

In PPM, go to Edit > Preferences, then go to the "Repositories" tab in the preferences window. Add the CPAN repositories to its sources by either selecting "uwinnipeg" from the "Suggested" list, or do what I did manually. Enter "CPAN" for name, and http://cpan.uwinnipeg.ca/PPMPackages/10xx/ to the location box, then click the "Add" button. You should now have DBD-mysql available for installation. Install it.

That should be it! As far as configuring MovableType goes, that's where I get off, because this installation was for a client who already knew how to use it, and already had his login information in the database (this was a server move).

Good luck!