Matt's Blog

Archive for the ‘Programming’ Category

DisAllow Indexing for “Random Post” Links

Thursday, May 31st, 2007

For those of you who use Matt Mullenweg‘s Random Redirect Plugin, this post will be useful for you.

If you’re not familiar with the Plugin, it will redirect you to a random post when you visit /?random.

I was searching Google with the top search terms to my Blog, and I noticed that for one of them, Google had the URL of the result as http://mattsblog.ca/
?random
. Which isn’t exactly going to be helpful, since the person who clicks on that result is probably not going to get the same Post that Google had gotten when they crawled the page.

So, how do you prevent this from happening? Simple, you tell bots not to index /?random. You can just add this to your robots.txt file:

User-Agent: *
Disallow: /?random

That’ll tell all the Bots that crawl your site (or, at least, the ones that follow the robots.txt standard) not to index /?random. Or, if you don’t want to do that, you can just add the following to your link for the Random Redirect:

rel="nofollow"

Now, hopefully those links to http://mattsblog.ca/?random will disappear out of search engines fairly quickly. 😀

Oh, and by the way, you can get a Random Post by clicking here.

Displaying Your Top 10 Posts

Sunday, May 27th, 2007

If you use WordPress, you have probably wondered if you can display your Top 10 Most Popular Posts before. Well, you can do just that by installing a Plugin that will record the number of hits an Article has. Then, uploading a simple PHP file that you can download for free.

The Plugin is WP-PostViews. The Plugin is free and is released under the GNU General Public License. So, simply install that Plugin by downloading it, extracting it and uploading it to /wp-content/plugins/.

Now this is where my script comes in. Okay, it isn’t totally my script. It’s a modified version of the Script BlueFur released for this same purpose. Except, I cleaned it up a bit and made it so it used WordPress functions, so it’s more “WP-Friendly” you could say. So, you can download my script here. The script is licensed under the GNU General Public License. Now, all you have to do is download that file (or copy and paste it into a new file) and name it something like topposts.php, or anything really, as long as it ends in .php, and not .txt. You may need to change the following lines, depending on where your WordPress installation is installed and where you put the script:

require_once('wp-config.php');
require_once('wp-includes/wp-db.php');

Then, upload the script. If you don’t want it to be a Top 10, you can change the value of $limit to something like 5 to have a Top 5.

You can see my Top 10 Posts here.

Get it? Got it? Good.

Enjoy. 😀

HTML 5, WTF?

Thursday, May 10th, 2007

I thought that XHTML was supposed to be the end of HTML, and the beginning of XHTML. Apparently, I was wrong.

I got a Newsletter today from SitePoint, as I usually do, and it was all about HTML 5. Yep that’s right, HTML 5. I thought the HTML line was dead, and the main focus was on XHTML (2). But, nope.

An HTML Working Group was created that anyone can join and add their opinions in the development of (X)HTML. This group is currently focused on the development of HTML 5.

I mean really, is HTML 5 really that necessary? It’ll just be something else for Browsers to support, and if we’re pushing to get something implemented into all Browsers, it should be XHTML. The way to do that is to prove to all the Browser developers that XHTML is a serious thing and is the real deal. The only way to that is to continue working on it.

I’m usually one to make Standard-compliant things (to a certain works-or-breaks point). But I won’t be using HTML 5. I’ll stick with XHTML 1.x, for now, thanks you. Besides, they don’t plan on being done with the HTML 5 recommendation until 2010.

Add Your Search To Internet Explorer and FireFox

Monday, March 19th, 2007

You’ve probably seen them, and maybe even used them, that handy little Search Box in the top-right of your browser. But, have you ever wondered how you can add your own Search there, and offer adding it to your visitors? Well, I’m going to show you how.

First of all, this is important, both Internet Explorer 7 (this won’t work in previous versions of Internet Explorer, since they didn’t have inline search) and FireFox use the Search Engine Provider standard, OpenSearch1.1. Because they use the same standard, you can use the same code in both Browsers to add a search provider. So, onto the details.

Okay, lets start with some background. XML is used to specify everything to do with your Search, so it’s fairly easy to implement. No Programming Language and Complicated Scripts here, folks, just straight XML.

First of all, if you want all the juicy details on all the possible “elements” available to use, go here.

Okay, here’s what we need to start with:

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">

The first line just tells the browser that you’ll be using XML encoded using UTF-8. The second line tells the browser what specification you’re using, and where to look for it.

Now, you need to start adding some details. First, you’ll need to specify the name:

<ShortName>Search Engine Name</ShortName>

That’ll be the name that shows up in the textbox in the corner of the browser when your Search is selected from the dropdown box. You can also add a <LongName> tag, but it’s not necessary, and I haven’t seen it used in Browsers yet. Now, for a description:

<Description>Search Engine Description</Description>

Not much to say about that, it’s simply the description of your Search.

Now, for Icons. Icons aren’t used in IE7, but they are, sometimes, used in FF. So, the code:

<Image type="image/x-icon" width="16" height="16">http://www.example.com/favicon.ico</Image> 
<Image type="image/png" width="64" height="64">http://www.example.com/favicon64.png</Image>

It’s best to include Icons of 2 sizes and formats, 16×16, 64×64 and .ico and .png. Note the full URL. You will need to include your full domain, you can’t just do /imagename.ext (since the browser won’t know where to look for the image).

Now, for the most important part, the URL.

<Url template="http://www.example.com/?s={searchTerms}" type="text/html" />

First, you’ll need to make a search (of any string) and then copy the URL and replace the string you searched for with {searchTerms}. Most likely, you’ll use text/html in type.

Now, to end the file, add this to the bottom of it:

</OpenSearchDescription>

All that code together would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> 
<ShortName>Search Engine Name</ShortName> 
<Description>Search Engine Description</Description> 
<Image type="image/x-icon" width="16" height="16">http://www.example.com/favicon.ico</Image>
<Image type="image/png" width="64" height="64">http://www.example.com/favicon64.png</Image>
<Url template="http://www.example.com/?s={searchTerms}" type="text/html" />
</OpenSearchDescription>

Now, the only left to do is to save the file and link to it.

You’ll want to save it as something.xml. I’m going to recommend addsearch.xml. Then, of course, you’ll want to upload that to your website.

Now, you’ll probably want to allow people to install this into their browsers ( 😉 ). So, all you need to basically do is add an onclick="" to a link:

<a href="#" onclick="window.external.AddSearchProvider('http://www.example.com/addsearch.xml');" title="Add Search Engine Name to Your Browser">Add Search Engine Name To Your Browser</a>

Now, you may want Visitors browsers to discover your Search Engine automatically. You can add this to the <head> of your page:

<link rel="search" type="application/opensearchdescription+xml" href="http://www.example.com/path/to/addsearch.xml" title="Search Engine Name" />

And that will have your visitors browser show either this:

Internet Explorer Discovered Search

Or this:

FireFox Discovered Search

I’ve added a Search Engine for this blog. Check it out.

Get it? Got it? Good.

Run IE7 and IE6 on the Same Computer for FREE

Thursday, January 4th, 2007

That’s right, you’ve read the title correctly. Microsoft is offering a, supposedly supported, way to run IE7 and IE6 on the same computer, all for free.

Lets start with how you can actually run IE7 and IE6 on the same computer. Sure, you could go all out and start hacking the Windows Registry and IE, but who feels like doing that? Besides, if you screw up, you could be screwed. 😛 Besides, Microsoft won’t give you support if you do this… Now, what does Microsoft recommend? Use Microsoft Virtual PC.

Now, if you know about Virtual PC, you would know that you would need to have 2 separate Windows XP licenses to be able run both IE7 and IE6. Now, nobody wants to go and spend money on another copy of XP just to have the convenience of have both IE7 and IE6 on their computer.

So, what is Microsoft doing about this? If you’re thinking nothing, you’re wrong. The IEBlog has recently announced that they are offering a free image of a valid copy of XP w/ IE6 for use with Virtual PC. But, the image will expire April 1, 2007. Also, now that Microsoft has release Virtual PC 2004 as a free download, this is FREE to do.

Download Virtual PC 2004 Download Virtual PC 2007 (about 20 MBs 30MBs)
Download the VPC Image Download Version 1.1 of the VPC Image(WARNING: about 500 MBs 400MBs 500-700 MBs)

I’ll be trying this out, when the VPC Image actually finishes downloading…

Update [January 4, 2007]: The downloads finished and I installed them. I’ve actually never used Virtual PC before, but it’s pretty cool. As its supposed to, it’s a valid copy of XP SP2 w/ IE6. Funny thing is though, the first time I opened IE6, it went to a page asking me if I wanted to download IE7. 😛 You think they would’ve made it so that a page like that wouldn’t show up, but w/e.

Update [March 23, 2007]: There’s a new version of Virtual PC and a new VPC Image. I’ve updated the links here for the new downloads. See my new post on it.

Update [August 20, 2007]: There’s a new version of the VPC Image out; for both the IE6 and IE7 versions. Check out my new post on it here