December 17, 2005
Creative Timestamps
I was updating my website just now and I added a little bit of PHP at the bottom to get the last modified date of the webpage from the server. That way, I could have an automatic "Page Last Updated on .... " message. For some reason my mind clicked over to Wikipedia, and I came up with this...
<?PHP
list($F, $d, $Y) = explode(" ", date("F d Y", filemtime($_SERVER['SCRIPT_FILENAME'])));
echo "Last Updated <a href='http://en.wikipedia.org/wiki/{$F}_{$d}' title='This day in history'>$F $d, $Y<a/>";
?>
Not only will that give you an automatic "Last Updated" message, but it will also link a page with everything that happened in the news on that day.
Posted by tylerhall at 02:25 AM | Comments (0) | TrackBack
December 15, 2005
CSS Spyglasses
Javascript and CSS can be combined to accomplish some pretty amazing things. Whether or not they're useful is a topic for another article. Today, however, I'd like to show you one of my favorite tricks. I call it the CSS Spyglass. (I wish I had a better name for it. Ideas?)
Here's a quick demo. Click the rabbit/tiger and then drag the small square around.
Neat, eh? It's actually pretty easy to implement. But before we get to the code behind it, let me explain what's going on visually.
Continue reading "CSS Spyglasses"
Posted by tylerhall at 08:33 AM | Comments (2) | TrackBack
December 13, 2005
Defining CSS Constants with PHP
IT'S PRETTY SIMPLE
I often find myself wishing CSS had constants like most programming languages. For example, at work, we have a specific shade of orange we use all the time. We call it Tricycle Orange. It's #F33500. We also have a magical shade of blue called CM Blue #346FB7.
So, anytime I write a CSS file which uses those colors, I have to type #F33500 or #346FB7. Just between you and me, I already have enough hex numbers floating through my head without having to remember these. Also, what would happen if our designer suddenly decided Tricycle Orange needed to be a few shades darker? I'd have to go through the style-sheets and change every occurence to its new value. Not very fun. Is there a solution?
Of course there is!
Using the magic of PHP we can define constants in our CSS files. That way, if we ever need to change a value, we only have to change it in one place. PHP updates the rest of the file for us - automagically! Here's how it works...
Continue reading "Defining CSS Constants with PHP"
Posted by tylerhall at 09:01 PM | Comments (1) | TrackBack
Include Recent flickr Photos with PHP
Putting your recent flickr photos on your website or blog is a quick and easy way to share them with the world and keep your site looking fresh. flickr gives you two options to do this.
- A small Flash movie
- Javascript
Both methods have their advantages. The Flash movie is very pretty. It's animated and sure to attract your readers' eye. (Whether or not that's a good thing is up for debate.) The javascript method is quick and dirty and has the added advantage of allowing you to customize the layout using CSS.
However, both ways have a common downfall - they rely on your readers' browser supporting either the Flash plugin or having javascript turned on. Granted, 95% of today's netizens will have at least one of these enabled (if not both), but they have the added problem of relying on the browser to do all the work. (Also, it's worth noting that the html created by flickr javascript is not standards compliant.)
It's my thinking that the server should do most of the heavy lifting. You shouldn't rely on your visitor's browser to do the rendering for you. It may not seem like much, but every extra bit of processing that you push onto the browser can really slow down an older machine or someone who's viewing your site on a handheld device. You want your site to look good and be responsive. Anything less could drive away repeat visitors.
With that said, there's a third alternative - one that doesn't rely on plugins and requires no client-side (browser) processing. By using PHP and a little elbow grease, we can read through the javascript which flickr provides us, pull out the elements we need, and style them to fit any website.
If you're one of those people looking for a quick solution to include on your blog or website, feel free to skip ahead to the finished product. Otherwise, continue reading to see how everything works.
Continue reading "Include Recent flickr Photos with PHP"
Posted by tylerhall at 02:05 PM | Comments (1) | TrackBack
