Use Only Genuine Interocitor Parts

Add to Technorati Favorites

Endorsements

Firefox 3

Eternally Up To Date Copyrights

Wednesday, July 25th, 2007 at 11:48 pm by Kenny

I can't tell you how many times, both personally and professionally, I've come across web sites that have out of date copyright dates. A living, breathing, up to date site should have a current copyright date somewhere on the page, usually in the footer. Changing the year is easy enough if it's static, but it's one of those things you have to remember to do (and you have to know how to do it). If your code isn't modularized (that is, if every page has the copyright date hard coded), then having to change these dates each year could be a very laborious process, even if you're savvy enough to use a global find and replace.

Why should you even have to make this update by hand? The web page should know that the copyright year is always the current year. There are a couple of ways to do this, depending on what you have available on your web server.

Concept

The concept behind this technique is very simple. You simple replace the year with a dynamically written number pulled from the supporting language's date functions. Here is the static code that we will start with:

<p>Copyright &amp;#169;2007 Your Web Site</p>

By the way, &amp;#169; is the © symbol.

Client-side Code Method

If you don't have any access to a dynamic server-side technology such as PHP, Java, Python, Perl, .NET, or some other programming language, then you will need to use Javascript. Here's an example of generating the year dynamically with client-side Javascript:

<p>Copyright &amp;#169;
<script type="text/javascript">
    var date = new Date();
    document.write(date.getFullYear());
</script>
Your Web Site</p>

The downside to this method is that, since the date is rendered by the browser, it is dependent upon the client's environment. If the user has Javascript disabled or if there is just some other unpredictable variable in the client's browser then the copyright year will be completely missing rather than just a year or two out of date. The other problem that arises is this: if the client's computer has the year set to 1963, then the copyright date on the web page will appear as 1963.

Server-side Code Method

If you have the ability to utilize a server-side technology, such as PHP, then you should. This method is preferred because you control the behavior and the date is written to the client as plain text. That is, it is rendered on the server and then streamed to the client as plain text. Here's an example in PHP of server-side dynamic copyright year text:

<p>Copyright &amp;#169;<?php echo date('Y'); ?> Your Web Site</p>

I could list out a dozen examples of how to dynamically generate the year, but I would probably end up leaving out the specific language that you are looking for. You can use this technique with any language. Yes, I know this isn't a ground-breaking technique, it's just printing the year, but I've seen enough examples of people with out of date copyright years that I thought this was a worthwhile tip to share. Good luck.


  • E-mail this story to a friend!
  • Google
  • bodytext
  • Technorati
  • del.icio.us
  • Slashdot
  • TwitThis
  • Furl
  • Fark
  • Reddit
  • StumbleUpon
  • Facebook

Finding A Jazz Guitar Sound

Monday, July 23rd, 2007 at 11:23 pm by Kenny

Oddly enough, much like with the modern country tone, a basic jazz guitar tone eluded me for a long time. Now, I fully admit that I don't tinker with knobs like I should. I tend to set the knobs on my amps, pedals, and guitar where I think they should be and then just leave them as opposed to tweaking knobs and listening to the results. This is probably why a basic jazz tone eluded me for so long.

Before I get into the specifics of finding a good jazz tone, let's look at what a good jazz tone is. Take a listen to this version of "How Deep Is Your Love" by Russell Malone and take careful note of where the guitar's tone fills up the tonal range.

[youtube bNvntOn7cOk]

You probably thought of words like "full" and "mellow" when you heard his tone. The difficult part for me to translate was that the tone was "full" in regards to the mid-range with balanced bass and treble. The hardest part for me to hear was that, in relation to how I typically prefer my guitars to sound for other styles, the tone on the guitar is rolled off (it's not on 10 or 11, if you're in Spinal Tap).

Guitar

There are some essentials and then there are some nice-to-haves. You can get a good jazz tone with pretty much any guitar and you can get a better jazz tone with some great guitars, but don't feel like just because you have an Ibanez RG or a Tele that you sound jazzy.

First off, you need some decent strings. For less than $10, you can go a long way in improving your tone. I won't play on anything lighter than .10s and I only use that on my Tele for country twang. Ideally, for jazz, much like blues, the heavier the string, the fuller the tone. Try .11s, .12s, or (dare I say it?!?!) .13s. I prefer D'Addario XL EJ21 strings (.12, .16, .24w, .32, .42, .52; the w on the G string refers to it being a wrapped string as opposed to a plain string), although many players prefer flatwound strings. To me, flatwounds strings, while mellow, sound dead. I like a little life in my strings.

Now that you have some decent strings, make sure you're using the neck pickup. The further from the bridge (without crossing the mid-way point) the pickup is, the more mellow (less twangy, less treble) the tone will be. Also, make sure that you roll the tone back. That is, rather than running your guitar's tone knob wide open on 10, turn it back to 6 or so, depending on the potentiometer in your guitar's tone knob. You want it right at the spot where the highs are more subtle but the tone hasn't gone flat yet. It's a sweet spot that takes some time to find if you don't know what you are listening for.

So that gets you the basics with any guitar. If you really want to swing with the big cats, then you'll want to pick up a full-hollow-bodied guitar, often referred to as a "jazz box", like an Epiphone Emperor Regent. This guitar has a single floating humbucker in the neck position, which is ideal for a very mellow jazz tone. If a jazz box isn't an option for you, then try something a little more versatile, but still at least semi-hollow, like a Gibson ES-335 or similar model.

Amp

When it comes to the amp, it's pretty simple. You want a very clean tone. There are occasions when you might want some mild drive, but that's more for fusion. A good clean tube amp like a Fender Deluxe Reverb or Fender Twin Reverb will work great if you prefer a tube sound. Many jazz players prefer a solid-state amp like a Polytone Mini-Brute or a Roland JazzChorus-120. Solid-state amps work well for jazz because the warmth of the tone is coming from the guitar and the amp is just making it louder. Also, solid-state amps are lighter and require little maintenance, which is great for the gigging musician.

As for the settings, if you have a pre-volume or gain knob, make sure it is at the lowest setting possible so you don't get any distortion. Start with all your EQ knobs flat (that means 5-6 if your knobs are the typical 1-10 range, 11 for Spinal Tap) and make minor adjustments from there depending on your guitar and the venue. You don't need to be very loud because jazz isn't typically loud and if you really need to crank it, your amp is usually run through the house PA. An optional setting, depending on your taste, is to run a little reverb on your amp.

Pedals

And that just about does it for the pedals. :) Well, kinda. The truth is that you really don't need any pedals for jazz. All the tone and sound comes from your guitar and your hands, which I'll get to next. There are a few nice-to-have pedals, but you don't really need any unless you're going to do a mixed set with some fusion or blues.

As with any setup, I like to run a Boss TU-2 Chromatic Tuner pedal for live tuning my guitars. I can't say enough good things about this pedal. It's fantastic and, yes, I know that sounds weird when I'm talking about what is essentially a utility pedal. Any pedal tuner will do and if you don't have a pedal tuner, just make sure you have easy access to a tuner of some kind.

I also like to run a volume pedal. This can help with hands-free fades both in and out of passages as well as volume swells for chord solos, etc. I like the Ernie Ball VP Jr.

If you're doing some ballads and you don't have any other chordal instruments (i.e. piano) to fill out the song, you might want to try a chorus pedal. I've used a few and they all have different flavors, so find one that you like. I have the Boss CE-5 Chrous Ensemble and the Visual Sound H2O Liquid Chorus & Echo. I like them both, although the H2O is a bit warmer, in my opinion.

Finally, if your amp doesn't have reverb, you might want to add a reverb pedal. I like the Line 6 Verbzilla, personally. It's really versatile and you can use it with many other styles as well from very subtle reverbs to massive, cavernous, ambient reverbs.

Again, any other pedals you might want to add would be to your personal taste, depending on what songs you are performing, but there really aren't any essential pedals for jazz.

You

Just like any style of music, the greatest impact on tone comes from your fingers, both right and left hands. You can affect your tone greatly through the precision, weight, and expressiveness of your hands. This is something that can't be taught (at least not from a web article) and must be learned through listening, mimicking, and practice, practice, practice. Even just thinking about the tone you want while playing can help translate this idea into your fingers and then into the guitar.

The only definitive piece of information I can share regarding tone and your playing is, just like using the neck pickup, you want to be away from the bridge to generate a warm, mellow tone. That is, your picking hand should be toward the neck rather than near the bridge.

Good luck with your search for a good jazz tone. If you've run across any secrets that you'd like to share, please feel free to comment or contact me directly and I'll add them to this article.


  • E-mail this story to a friend!
  • Google
  • bodytext
  • Technorati
  • del.icio.us
  • Slashdot
  • TwitThis
  • Furl
  • Fark
  • Reddit
  • StumbleUpon
  • Facebook

Posted in Guitars | No Comments »

Spam-proof MailTo Links

Friday, July 13th, 2007 at 11:03 pm by Kenny

I like providing links for e-mail on web pages, but I hate that spam-bots scrape sites looking for e-mail addresses linked in the usual manner. There are many hacks to try to avoid spam-bots

The Cander Method Version 1 (AKA: "Make The User Do The Work")

Named for a friend that I learned this from, one way to avoid this is to use ineffective links that require a person to modify address before sending it. Here's an example:

<a href="someuser_AT_somedomain_DOT_com">someuser_AT_somedomain_DOT_com</a>

…which appears as…

someuser_AT_somedomain_DOT_com

While this isn't spam-proof, it's spam-resistant. However, as I said, the user would then have to replace _AT_ with @ and _DOT_ with . in order for the e-mail address to be valid.

The Cander Method Version 2 (AKA: "Promiscuous Links, Strong Immune System")

The theory behind this method is "ah, screw it". Well, kinda. This method, also gleamed from the same friend, employs a standard mailto link that is completely vulnerable to spam-bots. Rather than try to trick spam-bots, you just resign yourself to the fact that spam is part of life and it's more important provide users with a good link. The spam protection is then handled by a good spam filter or by redirecting all your e-mail to a Gmail account, which is famously known for it's fantastic spam filtering. While I understand this approach, I still think that a good offense is the best defense.

The Corporate Method

Form e-mail is also a good option if your server supports it. That is, you can setup a script to take text from a standard HTML form and submit it via e-mail to you. This requires a bit more code and monkeying with the server to make sure that the web server is up and functioning and some web hosts may not even allow for this.

The Script-Redirect Method

Another method that I ran across (again, compiled from many sources and some original tinkering) is to provide a redirect that prevents spam-bots from scraping the address. The downside to this method is that you don't display the text of the e-mail address. The upside of this method is that the link works as-is and the user doesn't have to clean up the address before sending the e-mail. Here's how it works:

<a href="mailto.php?u=someuser&d=somedomain.com"
    onclick="target='_blank';"
    onmouseover="this.style.cursor='pointer';">E-mail</a>

Incidentally, the onclick and onmouseover events provide an XHTML Strict method of opening a new window without using extensive Javascript.

Place the preceding link wherever you'd like the e-mail link to occur. You'll notice that the link points to another script called mailto.php and it has a couple query string parameters. The u parameter refers to the username in the e-mail address (everything before the @) and the d parameter refers to the host (everything after the @).

Now that we have the link setup, we need the script that we are actually calling: mailto.php. This is the really easy part. It's one single line that pulls the query string parameters, puts them into standard e-mail address form, and redirects the browser to the mailto link. It's as simple as that. Here's the script for mailto.php:

<?php
    // pull values from query string and
    // redirect to a mailto link
    header("Location: mailto:$_GET[u]@$_GET[d]");
?>

While this may not fool all of the spam-bots out there, it should hopefully cut down on a significant bulk of spam that you might incur from posting a link to your e-mail address.


  • E-mail this story to a friend!
  • Google
  • bodytext
  • Technorati
  • del.icio.us
  • Slashdot
  • TwitThis
  • Furl
  • Fark
  • Reddit
  • StumbleUpon
  • Facebook

Make A File Dropbox For Quick Downloads

Friday, July 13th, 2007 at 10:30 am by Kenny

I frequently need to setup a quick and temporary link for file download either for myself or others, but I hate having to create a new page with links to files that are only going to exist for a few hours. Apache and other web servers often provide this functionality with directory browsing, but I usually want directory browsing disabled or the server that I'm using (that isn't mine) has directory browsing disabled and I can't turn it on.

I wrote (and by "wrote", I mean "wrote some, borrowed some from all over the web–yes, I know I'm not the first to write a script like this) this script to parse a directory and display links for all the files in that folder.

Take the script below and either create a folder called 'files' in the same directory as this file or you can modify the $filesDir variable to point to the location that you'd like to place your temporary downloads. For example, on my server, I have a folder under the root called downloads (http://myserver.com/downloads/) and I place this script in the folder and name it index.php. Within downloads/, I have another folder called files where I place the files for download.

If you want the files in the same folder as the script (that is, you want them all at the same level), I've included a check before the links are displayed to make sure that it's not displaying index.php. If you don't call this script index.php, you'll need to modify that piece of the code.

Let me know if you have any questions or comments. As with the usual disclaimer, I'm sure there are enhancements that can be made to this for both performance and security and the code comes as-is and without warranty. :)

<?xml version="1.0" encoding="iso-8858-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>Download Dropbox</title>
</head>
<body>
    <h1>Download Dropbox</h1>
    <hr />
    <?php
        $filesDir = './files/'; // where you intend to drop files
                                // relative to this page
        $files = array();
        $dir = opendir($filesDir);

        // get the list of files
        while(($file = readdir($dir)) !== false)
        {
            // ignore directories and special files that
            // we don't care about
            // .DS_Store is a Mac system file that I
            // don't want displayed
            if($file !== '.' && $file !== '..' && !is_dir($file) &&
                ($file !== '.DS_Store'))
            {
                $files[] = $file;
            } // end if test
        } // end while loop

        closedir($dir);

        if(count($files) < 1)
        {
            echo "<p>There were no files found.</p>n";
        } // end if test
        else
        {
            // display links for download
            natcasesort($files); // sort files

            echo "<ul>n";

            for($i = 0; $i < count($files); $i++)
            {
                if($files[$i] != "index.php")
                {
                    echo "<li><a href=\"files/" . $files[$i] . "\">" .
                    $files[$i] . "</a></li>n";
                } // end if test
            } // end for loop

            echo "</ul>n";
        } // end else test
    ?>
</body>

  • E-mail this story to a friend!
  • Google
  • bodytext
  • Technorati
  • del.icio.us
  • Slashdot
  • TwitThis
  • Furl
  • Fark
  • Reddit
  • StumbleUpon
  • Facebook

Finding A Modern Country Guitar Sound

Saturday, July 7th, 2007 at 11:54 pm by Kenny

For some reason, there are not a lot of resources (or at least not that many that I've found) that describe a general approach to getting a good modern country guitar sound. Of course, now that I've said that I'm sure I'll get a dozen people pointing me sites that I somehow missed. But anyway, I'd like to go over what I've learned from various readings, speaking to other guitarists, and from my own experimentation.

The first thing that you notice when you listen to guitarists like Brad Paisley, Vince Gill, Jimmy Olander of Diamond Rio, and others is how twangy and compressed their sound is. Now, if you aren't familiar with what a compressor does and what it sounds like, then saying that a guitar sounds "compressed" doesn't mean anything to you. A compressor limits the peaks and boosts the valleys of a guitar's signal. That is, it makes the quiet sounds louder and the louder sounds quieter, which evens out the attack. It also has the effect of making the sound very poppy and punchy, if that makes sense. I'll get back to achieving this sound a little later.

For the twang part of the sound sound, that typically means "more treble" in your sound. Make sure that your tone knob is maxed and use your bridge pickup on whatever guitar you're using. You can boost this treble sound by tweaking the equalization on your amp to favor the treble side. That is, start with your Bass, Middle, and Treble knobs "flat" or right in the middle. If your knobs go from 1 to 10, put them at 5 or 6. Now, to further boost the treble you can raise the Treble knob and set it at 8 or so. Also, if your amp has a Bright switch, flip that on. If your amp has a Presence knob, which is like the next step above Treble, you can turn that up a bit to your taste.

So far we have the very basics of a great country tone. Let's take it to the next level and discuss the various pieces of gear and how you can use them to shape your sound.

Guitars

Most country tricksters, as Johnny Hiland calls them, play Fender Telecaster which are known for their very twangy single-coil bridge pickups. You don't have to play a Telecaster to get a country sound, but using a guitar with a single-coil bridge pickup or a coil-splitting humbucker (which allows you to use the humbucker as a single-coil) definitely helps. Single-coil pickups have a much tighter, punchier sound that works well for country. That's not to say that you can't get a great country sound with a humbucker, but in general, most country guitarists play on Telecasters because of their bridge pickup.

Another common element that you might see on a guitar used by a country player is a maple fretboard, as opposed to a rosewood fretboard. There is some consensus that maple fretboards lead to a brighter sound. Not everyone agrees, but I've seen this to be true. However, and this is a BIG however, the difference is very subtle, in my opinion. I greatly prefer the feel of a rosewood fretboard so the extremely slight tone difference I found from a maple fretboard was definitely not worth it for me. Some people may feel that the tone difference is more noticeable, but after comparing the same American Telecasters with maple and rosewood fretboards, I could only barely tell the difference in tone but I could tell a great difference in feel and I prefer rosewood.

As for strings, I recommend a medium-gauge string, such as 9s, 10s, or 11s. For me, 9s are too light and 11s are a tad too heavy. You want a string that you can really bend on for those pedal steel double-stop oblique bends that are one of the signatures of country guitar. 10s have just the right amount of substance and tone while still allowing me to be flexible and bend as far as I need to.

If you're reading this, what I'm about to mention probably won't apply since it's a much more advanced feature, but I'll cover it anyway for reference. Some country guitarists have their guitars modified to include a B-bender or G-bender or even both. Until you see one, it's pretty difficult to understand exactly what it is, but I'll do my best to explain it.

Take the B-bender modification: from the front, the guitar looks pretty much unchanged except for a small ring behind bridge by the B string. The ball of the string is actually anchored in this ring rather than in the bridge, so the string goes past the bridge. Inside the guitar, there is a lever that is somehow (I've never actually seen the inside) connected to another lever by the neck-side strap post, which is spring-loaded. The shoulder strap then attaches to this new post and when you push the neck of the guitar down, the strap pulls against your shoulder and moves the lever which in turn pulls the lever by the ring and pulls the B-string tighter making the string ring sharp. It's almost like a whammy bar for a single string that is activated by pulling against the strap, or rather pushing the guitar down. This allows for pedal steel-style bends while playing. A G-bender is the same thing, except that it's typically pulling against the bridge-side strap post since most G-benders are implemented in addition to the B-bender. So with both, if you pushed down on the guitar on the neck and body, you'd get both the B and G strings to be pulled tighter, raising their respective pitches.

If that description was tough to follow, try taking a look at the pictures on this link: http://www.stringbender.com/bender/fenderb.html

Again, the B-bender and G-bender modification is not something that you will most likely need to worry about for now, but if you're completely befuddled by Jimmy Olander's licks, remember that he typically has a B and G-bender equipped guitar.

Pedals

In order to further shape your sound, you're going to want employ a few effects pedals. Many of these can be achieved by pedals, rack effects, studio processing, or digital modelers, but I'm going to stick to pedals for this article.

First off, any good pedalboard should have a tuner pedal. It doesn't seem that great until you have one and you realize how handy it is. That applies to any style of guitar; you need a pedal tuner. I recommend the Boss TU-2 Chromatic Tuner.

Second, one of the key elements in modern country guitar is the compressor. There are many compressors out there and they vary in price range. I have a Boss CS-3 Compression Sustainer which has worked well for me. Some people have complaints about it, but they seem to be pretty standard for all compressors, not just the Boss. I've heard good things about Visual Sound Route 66 which has a compressor and an overdrive in one pedal. Guitarists seem to always be comparing the Ross Compressor (no, that's not a typo when I tried to type Boss, it is meant to be Ross) to all other pedals as if it was the mold that all pedals should made from. The MXR Dyna Comp also comes up quite often. Whichever compressor you choose, you want a highly "squished" sound. Try checking the manufacturer for suggestions for a "squished" or country sound and what settings achieve that sound. I typically run the Attack setting at about 60% and the Sustain at about 75% on my CS-3.

Third, you'll want some kind of delay or echo pedal to give you that quick slap-back sound that many country guitarists use. You don't want much delay at all. Something very subtle will do well as it should almost sound like reverb. I use an inexpensive Danelectro Fab Echo pedal for my slapback because it's cheap ($20) and it isn't meant for much delay, which is just what I want. I can also achieve this sound with my more expensive, fuller-featured delay pedals, but I'd rather save those for longer delays and echoes. As for settings, as I said, you want the delay time very short and you want it to repeat only once. When you play a single note, it should sound like a very quick and subtle "BUH-dup".

Lastly, I highly recommend a volume pedal for assisting with pedal steel volume swells. I use the Ernie Ball VP Jr., which works great for passive instruments (if your guitar doesn't require a 9v battery for EMG active pickups or something similar, then you have a passive guitar).

As for order, follow the standard effects ordering process that has been written about in a zillion posts and articles online. You'll also probably want a mild overdrive pedal and a chorus pedal, but these, like the tuner, are essential pedals to any setup, in my opinion.

Amps

This is where you will probably hear the widest variety of opinions in getting a country sound. My recommendation is either a Fender Deluxe Reverb or a Fender Twin Reverb. I play a Twin Reverb ('65 reissue), because I also like to use it for blues and it has a bright switch which the Deluxe Reverb is lacking. If you start paying attention to what your favorite guitarists play, you'll probably see Fender, Vox, Matchless, and Dr. Z (for Brad Paisley) amps. The common theme among all these amps is that they are all-tube combos with either one or two 12" speakers. You don't need a high-gain full-stack for country and, in fact, it is detrimental to your sound if you do have one.

If the amp you choose doesn't have reverb, you can supplement that with a reverb pedal or dial in your slap-back echo for a little more fullness. As for settings, as I mentioned previously, you want to put some extra weight in the treble side of the amp and then you can adjust from there depending on your taste.

Now that you have a starting point for how to get that modern country guitar sound, you can play with it to achieve your own sound. Also, I've found that the most important aspect of your tone is your fingers. To sound cliché, it's all in the touch. Learning a few country licks and learning the feel will take you a long way with a little preparation in getting your ideal tone.

If you've discovered other secrets, I'd be glad to hear them and even supplement this article with that information, so please do share. Good luck!


  • E-mail this story to a friend!
  • Google
  • bodytext
  • Technorati
  • del.icio.us
  • Slashdot
  • TwitThis
  • Furl
  • Fark
  • Reddit
  • StumbleUpon
  • Facebook

Posted in Guitars | 3 Comments »

Turn Blogger Into Your Own Blog

Friday, July 6th, 2007 at 10:20 pm by Kenny

Recently I was working with a client who wanted a blog for their site but they didn't have the money (and I didn't have the time) for a completely one-off solution. The initially proposed solution was to simply make the "Blog" link point to a Blogger (which was purchased by Google a while back, if you missed it) site for the client. I didn't feel very comfortable with this idea because I didn't think it would look very professional to link to a free blogging site, so I started out by using the template editor that Blogger provides to mimic the client's site. While this was a better solution, it still didn't seem professional enough. The site was still a Blogger site; the URL was Blogger's and I couldn't exactly match the look-and-feel of the client's site.

This is when I remembered that Blogger (as many with many other sites) provides an XML-based RSS feed of each individual blog. Why not consume the RSS feed and redisplay the content on the client's site?! This technique allowed me to utilize the blog publishing and management tools from Blogger while full integrating the blog into the client's site. Now, instead of linking to an external site for the blog, I would just create a page that scraped the RSS feed, parsed the XML, iterated over the entries, and displayed the content.

Now for the meat. First, you need to create a Blogger account (if you have a Google/Gmail/G-anything account, that will work), then create a blog under that account and enter some dummy posts. Make sure that your blog has site feeds enabled; consult the Blogger help if you can't figure this out. Once you have that setup, your blog's feed can be found at http://someblog.blogspot.com/feeds/posts/default?alt=rss where "someblog" is the name of your blog in your URL. Also, you'll notice that I've appended ?alt=rss to the link. This is mentioned in the Blogger documentation in reference to forcing the feed into RSS format rather than Atom.

The following PHP code example shows a function that parses an RSS feed into a 2D array for display within your site. Note: the simplexml_load_file() function is part of PHP5, so you'll need to make sure that your server is running PHP5 if you want to use this code directly.

<?php
    function getBlogPosts($blogFeedURL)
    {
        $xml = simplexml_load_file($blogFeedURL);
        $posts = array();

        if($xml)
        {
            // get all posts
            foreach($xml->channel->item as $post)
            {
                $posts[] = array('title' => $post->title,
                                    'pubDate' => $post->pubDate,
                                    'description' => $post->description);
            } // end foreach loop
        } // end if test

        return $posts;
    } // end getBlogPosts function
?>

This next block of code utilizes this function and iterates over the 2D array to display the blogs. Also, I've incorporated the concept of paging where you can specify the number of posts to display at a given time and paging links are found at the top and bottom of each page.

<?php
    global $blogFeedURL; // defined globally, URL to RSS feed
    global $blogPostsPerPage; // defined globally, used for paging

    $posts = getBlogPosts($blogFeedURL);

    if(count($posts) < 1)
    {
        ?>
            <p>There are no posts currently available.</p>
        <?php
    } // end if test
    else
    {
        // get paging index from query string
        $firstPost = (array_key_exists('first', $_GET) &&
                                is_numeric($_GET['first'])) ?
                                $_GET['first'] : 0;

        // if first post index plus offset is more than total posts,
        // set last post to total number of posts
        $lastPost = (($firstPost + $blogPostsPerPage) > count($posts)) ?
                                count($posts) : ($firstPost + $blogPostsPerPage);

        // previous page link
        if($firstPost > 0)
        {
            $first = (($firstPost - $blogPostsPerPage) < 0) ?
                                0 : ($firstPost - $blogPostsPerPage);
            ?>
                <p><a href="<?php echo $_SERVER['PHP_SELF'] . '?first=' .
                                $first; ?>">Previous Page</a></p>
            <?php
        } // end if test

        // next page link
        if($lastPost < count($posts))
        {
            $first = (($firstPost + $blogPostsPerPage) > count($posts)) ?
                                count($posts) : ($firstPost + $blogPostsPerPage);
            ?>
                <p><a href="<?php echo $_SERVER['PHP_SELF'] . '?first=' .
                                $first; ?>">Next Page</a></p>
            <?php
        } // end if test

        // display only those for this page
        for($i = $firstPost; $i < $lastPost; $i++)
        {
            $title = $posts[$i]['title'];
            $pubDate = date('D, M j, Y g:i A', strtotime($posts[$i]['pubDate']));
            $description = $posts[$i]['description'];
        ?>
            <div>
                <p><?php echo $title; ?></p>
                <p><?php echo $pubDate; ?></p>
                <p><?php echo $description; ?></p>
            </div>
        <?php
        } // end foreach loop

        // previous page link
        if($firstPost > 0)
        {
            $first = (($firstPost - $blogPostsPerPage) < 0) ?
                                0 : ($firstPost - $blogPostsPerPage);
            ?>
                <p><a href="<?php echo $_SERVER['PHP_SELF'] . '?first=' .
                                $first; ?>">Previous Page</a></p>
            <?php
        } // end if test

        // next page link
        if($lastPost < count($posts))
        {
            $first = (($firstPost + $blogPostsPerPage) > count($posts)) ?
                                count($posts) : ($firstPost + $blogPostsPerPage);
            ?>
                <p><a href="<?php echo $_SERVER['PHP_SELF'] . '?first=' .
                                $first; ?>">Next Page</a></p>
            <?php
        } // end if test
    } // end else test
?>

As I said earlier, the great thing about this method is that someone else (Google and Blogger) did all the hard work for you. The downside is that you have to login to Blogger to post content, but I think that's a small price to pay for the amount of work that is already done for you. You get the layout-free content and you can style it yourself and embed it in your own site as you see fit. Alternately, you could of course do this in Python, Java, .Net, or any language that you can make an HTTP call and then parse the XML.

As for the usual caveats, I'm sure there are ways to improve the security, add layers of error checking, use objects instead of a 2D array, so feel free to modify as you wish. This is where the "This software is presented as-is and without warranty…" bit goes.


  • E-mail this story to a friend!
  • Google
  • bodytext
  • Technorati
  • del.icio.us
  • Slashdot
  • TwitThis
  • Furl
  • Fark
  • Reddit
  • StumbleUpon
  • Facebook