PHP Tutorials
Google URL Shortener PHP Class
Google has had a URL shortening domain for quite a while now but it wasn't until recently that Google exposed the URL shortening API to the public. I took a few minutes to review their API and created a very basic GoogleUrlApi class that will shorten long URLs and expand shortened URLs.
Force Login to View WordPress Blog Pages
I was recently working on a private / "closed" website that featured WordPress. User management is a must and content can only be seen if the user is logged in. I was shocked to find that WordPress didn't provide an option to accomplish this task. Luckily a quick snippet in the header of my template allowed me to force login to view content:
WordPress JSON API Plugin
Ever since I moved to a mostly-JavaScript job, I've become more and more enamored with the simplicity and usefulness of JSON. Now I want everything available in JSON format, and when I encounter a service which doesn't provide a JSON API, I have a fit. I was recently brainstorming a way to place my website into a Dojo/Dijit widget and realized that WordPress doesn't provide a native JSON method of retrieving post information. Enter the awesome JSON API plugin.
Quick Tip: Object Indexing vs. Array Collection
Let's say that we have one large text document and we have a a bunch of keywords that we want to parse the document for. We don't care how many times times the keyword appears — we just care that it's been used. When we find a keyword, we need to record that keyword been found so that we may check at a later time.
Change Category Slug within WordPress
When I first started this blog, I set the category "slug" to "sugar." Why sugar? Because a lot of a good thing is candy; thus, a bunch of MooTools tutorials is as sweet as sugar. While I get a giggle out of calling my categories sugar, Google doesn't find it nearly as funny, nor does Yahoo or Bing. In an effort to increase my SEO, I wanted to change my category slug to "tutorials." That's where the awesome Redirection plugin and a simple regular expression comes into place.
Build HTML Tables From MySQL Tables with PHP
I was recently completing a project which required that I build a series of HTML tables which would represent all of the tables within a MySQL database. I didn't have anything created but after a few minutes I had exactly what I needed. Hopefully this helps you out!
Create a “Recent Posts” Module Outside of WordPress
The websites I create are never powered by WordPress. Sure I may add a blog to the website but I've never created a client website that was run by the powerful blogging software. In an effort to tie the website and blog together, I'll usually do some quick PHP/MySQL programming to pull in recent blog post titles and links to the individual posts. Here's the PHP and MySQL that accomplishes that task.
Create Bit.ly Short URLs Using PHP: API Version 3
Bit.ly is a great URL shortening service. I love their reliability, shortness of the URL, and the information they provide about a given URL. Recently Bit.ly updated their API to version 3 so I thought I'd update my original Bit.ly post. Here's how you can create short URLs and expand short URLs using Bit.ly.
iPad Detection Using JavaScript or PHP
The hottest device out there right now seems to be the iPad. iPad this, iPad that, iPod your mom. I'm underwhelmed with the device but that doesn't mean I shouldn't try to account for such devices on the websites I create. In Apple's developer tip sheet they provide the iPad's user agent string:
Automatically Generate a Photo Gallery from a Directory of Images: Updated
Two years ago Chris Coyier wrote an outstanding tutorial detailing how you can generate a photo gallery based on the images within two directories: a thumbnails directory and an originals directory. I've decided to take his tutorial a step further by showing you how to generate thumbnails for the gallery using PHP. I've also implemented a MooTools lightbox: Smoothbox. The following code will show you how to create a beautiful photo gallery by simply dumping your photos in a directory.