No More CSS Hacks: PHP Browser Detection

Wednesday, May 28th, 2008

You can’t make your page render correctly in every browser. It just isn’t possible. Between several versions of the bug-ridden Internet Explorer (why can’t Microsoft just switch to Gecko or WebKit?) and a sprinkling of older browsers, there are too many bases to cover. Internet Explorers 6 and prior are notorious for their bad CSS implementations (IE7 is better, but it still has a ways to go), and if you tweak your CSS to look right in them, chances are you’ll create another problem somewhere else. When does the endless cycle of fixing things end? When you give up and say “it’s just not going to work in all browsers.” Now, you don’t want to give up too soon, since there are still a lot of people on IE6, but you have to know when to call it quits.

And don’t forget about mobile browsers. Sure, their improving, like Apple’s mobile Safari browser on the iPhone, but it’s still a lot easier to use a mobile-specific version of a site than zooming and scrolling around on the tiny screen.

As usual, PHP has a solution. That solution comes in the form of the global variable $_SERVER['HTTP_USER_AGENT']. It holds a string that contains a bit of information about the browser and platform a user us using. By searching through the string, you can figure out what browser your users are browsing with, and write-in the right code depending on the browser. You can do this in as simple, or as complicated, of a way as you want. (more…)

Using WordPress Custom Fields to Control AdSense Sizes

Thursday, March 13th, 2008

Two of the most common AdSense placements on blogs are

  1. A rectangular ad (such as the 250×250 unit) in the post, floated to the left, with the text wrapping around it.
  2. A 468×60 “banner” unit between the post title and the content.

In some posts, though, the floated ads get in the way of other elements, such as images. Suppose you want to have an image floated to the right, at the top of your post. That could conflict with your ad, couldn’t it? If the image is wide enough, it would run right into the ad. Or what if you wanted to have a wide image above the content, like on Copyblogger? That left-floated ad would get in the way. What’s the solution? No, you don’t need to switch to a 468×60 ad, which often doesn’t perform as well as the floated ad. It’s time for a little WordPress magic. (more…)

How to Feature Your Best Posts in Your Sidebar

Friday, January 25th, 2008

Looking for a way to feature some of your better posts? Here’s a method I’ve been using for a few months (visible on the index and the screencap to the right).

The five most recent posts that I’ve marked as “Featured” will appear in the list, along with a “view all” option that takes the clicker to a custom date-based archive.

How does it work? It’s done with multiple loops and categories. (more…)

Zenphoto - Lightweight Web Gallery Script

Sunday, January 20th, 2008

Tired of the bloated Coppermine Photo Gallery? The much lighter Zenphoto gallery script may be a good alternative.

The compressed download is under one megabyte, and the installation looks fairly simple. Just upload via FTP, and run the installation script.

The installed gallery is responsive and clean. Don’t take my word for it, though. Look at the demo gallery.

The script is fairly new, and is still evolving. Some features, like RSS support, have just been added.

If you need a gallery (for a design portfolio, to show off your photos, etc), then be sure to check-out Zenphoto.

Start Using Polls on Your Blog

Tuesday, January 15th, 2008

Polls are a great way to solicit opinions, and add some community to your site.

With a poll, a user can just click a button to give you their two cents. Meanwhile, it takes a lot more effort to leave a comment. Which do you think your readers prefer? While comments allow them to say anything they want, polls enable a quick multiple-choice response (which can be very useful). Also, I’ve found that blog posts with attached polls tend to generate more comments.

Once you decide you need a poll, you need to actually add one. You have plenty of choices for implementing your poll. Here are a few of the better services/scripts: (more…)

When Should You Use AJAX?

Wednesday, January 9th, 2008

AJAX, or Asynchronous JavaScript and XML, was probably the most-hyped web programming technique in the last two years. It’s no surprise, as it enables you to do a lot that couldn’t have been done just a few years ago.

AJAX is being used in more and more places, often when it doesn’t need to be…and when it shouldn’t. With all the talk about how you can use AJAX for everything, the real question is when should you.

You should use AJAX in places where it will improve the user experience. One example is with polls. Why should a full pageload be required just to vote in a poll (or view the results)? That’s a waste of your users’ time, and a waste of your server resources.

Do not use AJAX for loading your main content, though. It’s not a good idea. I’ve seen a few sites that have tried it, and it doesn’t work that well. You have to come up with extra solutions for search engines, because they can’t understand your JavaScript trickery (you thought the dreaded “text-only version” link only applied to Flash sites? ). You also cause problems for people using some browsers (Safari, IE5, etc).

Basically, you want to use AJAX for things where an extra pageload would be irritate the heck out of everyone. Suppose you have a star-rating system, like on Netflix. Wouldn’t it be horrible if you had to sit through a page refresh every time you rated a movie? Use your own judgment.

MiniAjax

Monday, January 7th, 2008

Looking for some AJAX scripts? MiniAjax is a gallery of “nice looking simple downloadable dhtml and ajax code.”

The one-page site shows 62 (to date) entries for various useful scripts. There are star-rating systems, modal dialogs, heatmap generators, poll scripts, tabbed interfaces, and more. Thumbnails make the site easy to browse.

If you’re looking for a specific type of script, or if you just want to see what’s out there, be sure to take a look at MiniAjax.

roScripts - Helping Programmers Program

Friday, December 28th, 2007

roScripts is a blog/forum/Digg-for-scripts. Their “articles” section has several categories worth of coding tutorials (PHP, Flash, AJAX, HTML, etc). Then they have the “scripts” section, where you can easily find pre-made scripts to suit your purposes. The interesting part, though, is that they’re sorted in a Digg-like manner. You can vote-up scripts you like, and “bury” the ones you don’t.

roScripts has changed a lot since their launch, and they keep getting better.

What Can You Do to Make the Most of Shared Hosting?

Sunday, December 9th, 2007

In response to Keep track of your shared hosting performance at the Royal Pingdom blog.

Many blogs and small website are hosted on shared servers. Unfortunately, those bargain hosting plans have their share of problems. Most of the problem come from overselling, but that doesn’t mean there’s nothing you can do to improve your site’s performance. This guide will briefly detail some of your options.

Scripts

PHP scripts can eat-up system resources sometimes. Simple scripts, like the use of the include() or require() functions to include bits of XHTML temlate throughout your site, don’t take much processing time, but more complex scripts (like Content Management Systems) can be really taxing under heavy traffic. (more…)

A/B Testing: Optimize Your Ads

Wednesday, November 14th, 2007

The problem with AdSense is people tend to ignore them. As a webmaster, you have to continually update your ad placement to prevent this “banner blindness.”

How can you tell what the best placement and ad format is? You use A/B Testing. When you A/B test, you randomly show your readers one ad or the other, and track which gets more clicks. It’s easy to do, and will improve your earnings.

First, generate to ad code snippets. Make sure both ad formats are assigned to unique (and descriptive) channels. That way you can tell how many clicks each ad block gets. For example, put your 200×200 square ad in a channel called “200×200 AB Test” and your 250×250 ad block in “250×250 AB Test.” Paste the generated codes into notepad for later use. (more…)


Close
E-mail It