Tag Archives: links

Building iTunes Links

Have you ever wanted to link to an iTunes page? It’s easy enough to copy a long, nasty-looking URL like http://itunes.apple.com/us/album/yours-truly/id310905907 right from the application by right-clicking on the album art or title. This works well enough if you’re manually linking to an album or iPhone app from a blog post, but what if you need something a bit more user friendly?

It’s not documented terribly well, but you can create much nicer short “search” links using the itunes.com domain. Here are a few examples:

You can even combine the search links with your iTunes affiliate ID, if you know how to do it right. It looks something like this:

http://itunes.com/artist/album?partnerId=30&siteID=YOUR_AFFILIATE_ID

Now for the fun part… Wouldn’t it be neat to be able to generate the links automatically? I’m doing that over at Folk Music Site (a fun project I put together last summer, as I thought it would be neat to have a directory of noteworthy folk musicians). Here is some simple PHP that will generate iTunes links on-the-fly:

function get_itunes_link($artist, $album) {
 $affiliate_id = ''; //Linkshare affiliate ID for iTunes
 $artist = clean_itunes_string($artist);
 $album = clean_itunes_string($album);
 $link = "http://itunes.com/{$artist}/{$album}?partnerId=30&siteID={$affiliate_id}";
 return $link;
}

function clean_itunes_string($string) {
 $string = strtolower(str_replace(' ', '', $string)); //remove whitespace and makes everything lower-case
 $string = str_replace('&', 'and', $string); //Replace ampersands with the word 'and'
 $remove = array('!', '¡', '"', '#', '$', '%', '\'', '(', ')', '*', '+', ',', '\\', '-', '.', '/', ':', ';', '<', '=', '>', '¿', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~', '©', '®', '™');
 $string = str_replace($remove, '', $string); //Remove special characters that iTunes doesn't like
 return $string;
}

echo get_itunes_link('Feist', 'The Reminder');

Note: iTunes links should not have accented characters like á or ü. They should be replaced with their base ASCII counterparts (“a” and “u” respectively). The above code does nothing to sanitize these characters, so you might run into problems unless you write some additional logic to handle that. If you’re using a framework like Kohana, you might have a convenient helper function like utf8::transliterate_to_ascii().

Google Canonical URLs

Finally, the solution for our duplicate content worries is over! Google now supports a new method to specify a canonical URL for your page. This “hint” suggests that Google use this page as the original, and ignore duplicates elsewhere on your domain.

You simply add the fully W3c-compliant <link> tag in your header, and have it point to the permalink for a given post. Google will most likely rank that page in their results, and ignore others. That should help out your ranking overall.

<link rel="canonical" src="http://www.example.org/your/permalink/page/" />

Obviously you’ll want some way to integrate this with your CSS. Some will want to roll their own solution, but if not, there are already prefab options available.

The Secret to Getting Traffic: Link

Forget all about PageRank. Fill your posts with links to related posts, on your blog, and more importantly, on other blogs. Don’t hoard PageRank, and try to keep visitors on your site. Send them to other sites, and hope they come back. If you have a good blog, they will.

A little counterintuitive, isn’t it? You send your visitors away, in order to get more?

Yep. It works because, by linking to someone, you’re ending up on their proverbial radar. If they notice that you’ve linked to them, there’s a good chance they will read your post, and possibly link back. If everyone was stingy with their links, the web wouldn’t work very well, would it? You wouldn’t have traffic from people linking to your posts. As a reader, even, you would have a much harder time finding things, and would miss-out on posts that you would find useful. Without links, the web wouldn’t be the web.

But the New York Times doesn’t ever link to anyone!

No, they don’t. Most of the Dead-Tree Media (or Dinosaur Media) don’t really understand the web. They don’t really like it much either. They would prefer to hang onto their existing, failing, business model. Since they can’t do that very well, they try to “break the web,” and make it work the way they want. They hoard PageRank, and try to keep people on their site, where they’ll be bombarded with ads, and help to inflate their traffic stats. Oh, and sometimes they don’t like it when you link to them either…

Link, and you will get links. That’s how the blogosphere works.

DBT Group Project: Some Tutorials Worth Reading

I’m participating in the Daily Blog Tips tutorial contest. Since contestants are supposed to post a list of their favorite entries, I’m going to post mine here. I’ve rounded up the ones I like, which I think readers of Webmaster-Source may find useful.

Wondering what post I submitted? How to Feature Your Best Posts in Your Sidebar, which I wrote not long after seeing the contest. It was in my mental list of “Things That Would Make Good Tutorial Posts, If I Can Remember Them.” The contest got me to invest some time actually writing it (Thanks, Daniel!).

Here are my favorites from the list of entries (and I say again that you may find them useful):

Continue reading →