Why? What? Huh?

My blog, Mister Crunchy, is really two blogs. On the left side, I write longer pieces. On the right, I post links to stuff I think is worth linking. I used to publish all of it in a single blog, but I didn't like that when I posted lots of links they would push my longer pieces down and out of sight. I like my original work to stay visible. I'm vain that way.

I thought it would be easy to put two blogs on one page. I expected that maybe Blogger would have a setting somewhere that would let me do it. Alas, Blogger didn't support it and none of the Web programming books I read included a chapter on putting two blogs on a page. So I read up on server-side scripting and then farted around until I got something working.

I don't claim that the method I'm going to show you is the best way to put two blogs on the same page or the only way. What I can say is that it works.

PHP

This method uses a scripting language called PHP, which stands for "PHP Hypertext Preprocessor." That's right, the acronym refers to itself. If your blog's host doesn't support PHP, you either need to upgrade your hosting account to support it, or you need to find a new host. This method won't work with Blogspot or probably most other blogging tools which host your blogs for you. You need your own host.

PHP statements are pieces of code, little programs, really, that your web server executes before sending a web page out to a visitor. One of the things we can do with PHP is write a little program to grab an external text file and slap it into the middle of your web page before sending it out to your visitors. Once we've got PHP code grabbing one file, what's to stop us from grabbing two? Nothing. Like every other Web page, a blog is just a fancy text file. So if we can include two text files on our page, we can include two blogs.

How It's Done

Ready to learn the secret? Here it is:

<?php include 'filename.txt' ?>

That's it. That one line is a PHP command which tells the server to replace it with a file called "filename.txt". Actually, it's not quite that simple. You also have to change your page's filename so that the extension is ".php" rather than ".html" or ".htm". Changing that extension tells the PHP-supporting web server to look for PHP code to execute.

Now that you know how to include external files on your web page, it's pretty easy to put two blogs on there. You build a page with all your formatting and layout. You include PHP statements instructing the server to insert two text files into your page, and you set up two blogs in your blogging software with those filenames. It's probably a good idea to remove everything from your blog templates up to and including the <body> tag at the beginning, and everything from the </body> tag onward from the end. Having multiple <head> or <body> tags in an HTML file gets confusing for some browsers.