Introduction to RSS

RSS stands for Really Simple Syndication, and it is the most popular feed standard on the web today. You may have seen links on some of your favorite websites (including this one) that advertise their RSS feeds for you to subscribe to. If you’ve never used a web feed before, you may be surprised how simple they really are.

RSS Icon

RSS is a family of standardized formats for web content that allow you to check your favorite websites for new material all at once, without having to go to each site individually. Everything is brought directly to your feed reader when it’s made available by the publishers.

How does it work?

RSS is essentially just an extension of eXtensible Markup Language (XML), a set of standards that allow for easy organization of content for consumption by machines. It details the relationships between the information so that it can be translated by the computer in a way that makes sense to human readers. A simple RSS document might look like the following:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
	
	<title>Title of the feed</title>
	<link>http://danielsellergren.com/rss</link>
	<description>Description of the feed's content</description>

	
	<pubDate>Mar, 21 2010 00:16:45 EST</pubDate>
	<category>Web development</category>
	<language>en-us</language>
	<copyright> © 2011 Daniel Sellergren</copyright>

	
	<item>
		<title>Title of the first article</title>
		<description>Description of first article</description>
		<link>http://danielsellergren.com/first-article</link>
		<pubDate>Mar, 21 2010 00:16:45 EST</pubDate>
	</item>

	
	<item>
		<title>Title of the second article</title>
		<description>Description of second article</description>
		<link>http://danielsellergren.com/second-article</link>
		<pubDate>Mar, 11 2010 00:08:17 EST</pubDate>
	</item>
</channel>
</rss>

One of the major advantages to RSS/XML markup is that it mimics the hierarchical way in which humans often organize information. Outer <xml> and <rss> tags tell what type of document is to follow, and the <channel> tags enclose the content itself. Inside there are also tags for <title>, <description>, and <link> which are required attributes for describing the overall content of the feed itself. There are also many optional fields that you can include to enhance your feed by giving information about publication date and category. For a full list of <channel> tags you can click here.

Within the <channel> tags there can be numerous <item> tags that denote individual articles within the feed. Each one has a <title>, <description>, and <link> just like the feed except tailored to relate to a specific article. These also accept many optional fields that can allow the reader to have more detailed information.

Using a reader

There are many options available for reading RSS feeds, including some that you may already have access to. For example, most of the major web browsers such as Firefox, Safari, and Internet Explorer have built in RSS readers that you can use without even opening another application. Chrome is notoriously missing its own built in reader, most likely due to the popularity of the Google Reader, their web-based RSS client.

Adding a feed to your reader is generally as simple as clicking the link provided on a website. If you use your browser’s built in reader, it will add it automatically to your list. Some sites will also provide a set of links that will automatically add their feed to one of your web-based readers such as Google’s. If all else fails, you can simply copy and paste a link to the site’s RSS feed into your preferred reader and you’re good to go!

RSS for your site

Adding an RSS feed for your site is generally simple if you use a Content Management System (CMS) like WordPress or Joomla! Many have built in RSS capabilities, but any major CMS that doesn’t will certainly have an appropriate plugin that updates feed when you update your site. For WordPress automatically maintains an RSS feed for you in several different versions which you can link to by using the following commands:

<?php

	/* RDF/RSS 1.0 feed */
	bloginfo('rdf_url');
	/* RSS 0.92 feed */
	bloginfo('rss_url');
	/* RSS 2.0 feed */
	bloginfo('rss2_url');
	/* Atom feed */
	bloginfo('atom_url');

?>

If you are not using a CMS, you’re going to have to either write code into your application that generates the feed for you, or update it manually each time you make an update to your site. This can be very time consuming, which is why many sites prefer to use an established CMS if they are regularly producing a large amount of content.

Further reading

For more information please visit the following resources.

 

Using Modernizr to Determine HTML5/CSS3 Support

Modernizr is an open source, MIT-licensed Javascript library that allows web designers and developers to start using HTML5 and CSS3 features while still having precise control over older browsers. While the site loads, it automatically checks the browser’s support of new HTML features like <canvas> and <video> and new CSS properties like border-radius, box-shadow, and text-shadow. It then provides the results in a global variable, and adds classes to the <html> element which allow you to handle the CSS and Javascript differently for incompatible browsers.

Getting started is easy — you just need to download the latest version of the library, place it in your main or /js directory, put a class of “no-js” in your <html> tag and link to the file address in your <head>.

<html class="no-js">
<head>
	<title>Using the Modernizr library</title>
	<script type="text/javascript" src="js/modernizr-1.7.min.js"></script>
</head>
<body>
</body>
</html>

The file itself is only 3.7 kilobytes and the script runs automatically without any sort of initialize() function for you to run. After the script is loaded, you can test for various support by checking the properties of the global Modernizr object.

if (Modernizr.canvas) {
	// We can play with the <canvas>!
} else {
	// Sad time! No <canvas>!
}

Additionally, you can use different CSS depending on whether there is support of an element by using the new <html> classes that Modernizr adds. A full list of the Javascript properties and CSS classes is available in the Modernizr documentation.

/* Happy background for canvas support */
.canvas {
	background: yellow;
}
/* Sad background for no canvas support */
.no-canvas {
	background:
}

The last thing that Modernizr takes care of for you is creating dummies for the new HTML5 Semantic Elements. This allows less supportive browsers to recognize (and let you style) elements like <header>, <footer>, <nav>, <section>, and <article>. This keeps Internet Explorer from inserting unrecognized elements into the DOM as empty nodes with no children. You can now use the newest HTML5 elements in your markup, and style them in your stylesheet, without having to worry about whether they are supported.

That’s all there is to it, so get started using HTML5 today!

CSS3 for Block Elements: Shadows, Corners, and Gradients

With most modern browsers starting to support CSS3 standards, designers and developers now have access to some pretty cool styling tools that were once limited to Photoshop. Commonly used design elements such as shadows, rounded corners, and gradients can now be rendered in the browser without need for custom images. There are still some cross-browser issues that have to be taken into account, but the overall implementation is still very simple.

Box Shadows

Box Shadows are an easy way to add depth to your design but up until now they’ve required the use of images, extra <div>s, and the z-index property. Now you can add your own shadows to any block element with just a few lines of CSS.

#anyBlock {
	/* Box shadow */
	-moz-box-shadow: 2px 2px 3px 1px #AAA;
	-webkit-box-shadow: 2px 2px 3px 1px #AAA;
	box-shadow: 2px 2px 3px 1px #AAA;
}

The pixel values represent horizontal offeset (positive values move shadow right), vertical offset (positive values move shadow down), blur radius, and spread distance. The blur radius and spread distance values can be omitted if so desired. The final value dictates the color of the shadow in either hexadecimal #AAAAAA format or rgb(170,170,170) format. Some browsers also support the rgba(170,170,170,0.5) format which adds an opacity value. Our example box looks like this so far:

CSS3 Block Level Box Shadow

Rounded Corners

Another design element that has become very popular in the “Web 2.0” design generation is rounding the corners on block elements to give a smoother, cooler feel. This can be done with CSS3 using the border-radius attribute either to individual corners or all at once.

#anyBlock {
	/* All corners */
	-moz-border-radius: 15%;
	border-radius: 15%;
}
#anyBlock {
	/* Top left corner */
	-moz-border-radius-topleft: 50px 100px;
	border-top-left-radius: 50px 100px;
	/* Top right corner */
	-moz-border-radius-topright: 100px 50px;
	border-top-right-radius: 100px 50px;
	/* Bottom right corner */
	-moz-border-radius-bottomright: 50px 100px;
	border-bottom-right-radius: 50px 100px;
	/* Bottom left corner */
	-moz-border-radius-bottomleft: 100px;
	border-bottom-left-radius: 50px;
}

Notice that you still have to account for the Mozilla prefix -moz-, but for the most part it is still very simple. The pixel and percentage values determine how far away from the corner the rounding will begin. When two values are given, the first represents horizontal offset and the second represents vertical offset. The is also a shorthand method for specifying all four corners at once:

#anyBlock {
	/* Shorthand for all corners */
	border-radius: 50px 100px 50px 100px / 100px 50px 100px 50px;
}

The first four values describe the horizontal offset for the top-left, top-right, bottom-right, and bottom-left corners. The four values after the / describe the vertical offset. By varying the horizontal and vertical offsets on each corner you can come up with some really unique shapes like this:

CSS3 Block Level Rounded Corners

Gradients

One last design element that is already being implemented in modern browsers is the color gradient. It is another option that allows you to add depth and detail to your websites without creating inflexible background images. Once again, Webkit browsers (Chrome & Safari) and Mozilla browsers (Firefox) both support CSS3 gradients but unfortunately not under the same standards.

#anyBlock {
	/* Non-CSS3 browsers */
	background: #EEEEEE;
	/* Chrome/Safari */
	background: -webkit-gradient(linear, 0 0, 0 100%,
                             from(#EEEEEE), to(#AAAAAA));
	/* Firefox */
	background: -moz-linear-gradient(top, #EEEEEE, #AAAAAA);
}

With the Webkit gradient we are defining five parameters: type of gradient (linear), coordinates (x, y) of starting position, coordinates (x, y) of ending position, starting color, and ending color. The Mozilla gradient defines the type of gradient -linear- within the vendor extension, then requires a starting position (top, bottom, or -Xdeg), a starting color, and an ending color. You can add multiple colors by using color-stops:

#anyBlock {
	/* Non-CSS3 browsers */
	background: #EEEEEE;
	/* Chrome/Safari */
	background: -webkit-gradient(linear, 0 0, 0 100%,
        from(#EEEEEE), color-stop(#CCCCCC), color-stop(#AAAAAA));
	/* Firefox */
	background: -moz-linear-gradient(top, #EEEEEE,
        #CCCCCC 50%, #DDDDDD 75%, #EEEEEE 100%);
}

Finished Product

So let’s take a look at one final example to see how everything works together.

#anyBlock {
	/* Box shadow */
	-moz-box-shadow: 2px 2px 3px 1px #AAA;
	-webkit-box-shadow: 2px 2px 3px 1px #AAA;
	box-shadow: 2px 2px 3px 1px #AAA;
	/* Rounded corners */
	-moz-border-radius: 5px 10px 5px 10px / 10px 5px 10px 5px;
	border-radius: 5px 10px 5px 10px / 10px 5px 10px 5px;
	/* Background gradient */
	background: #FFFFFF;
	background: -webkit-gradient(linear, 0 0, 0 100%, from(#FF0000), to(#AA0000));
	background: -moz-linear-gradient(top, #FF0000, #AA0000);
}

Which gives us a pretty snazzy looking box that uses nothing but CSS3!

CSS3 Block Level Color Gradient

How to Structure a Simple Site with PHP

Using PHP to structure your small business or personal site is a very simple process that can save you hours of hassle when it comes time to make changes. By dynamically creating each page out of multiple source files, changes made to one section of code can ripple throughout the entire site. Think of it in the same way that CSS allows for sweeping design changes by altering a single stylesheet.

Rather than creating an .html file for each page with all the site architecture repeated on each page, we’re going to separate out common, reusable sections such as the header, footer, and navigation menu. We’re going to create a main file named index.php, and several subfiles named header.php, nav.php, and footer.php. Let’s take a look at index.php so we can get an overview of what we’re doing.

<!doctype html>
<html>
<head>
	<title>A basic site architecture</title>
	<!-- Include all CSS, JS, and meta information -->
</head>
<body>
	<?php require("header.php"); ?>
	<?php require("nav.php"); ?>

	<div id="main">
		<!-- Main content goes here -->
	</div>

	<?php require("footer.php"); ?>
</body>
</html>

The parts of our site that are common to all pages have been separated out so that they can be reused rather than copied. In lines 8, 9, and 15 we load three files containing the code for our header (logo and other graphics), navigation menu, and footer. When you view the index.php file in a web browser it will assemble the four files into one, and will appear this way if you choose to view the page source. Take a look at the final assembled index file:

<!doctype html>
<html>
<head>
	<title>A basic site architecture</title>
	<!-- Include all CSS, JS, and meta information -->
</head>
<body>
	<!-- header.php -->
	<div id="header">
		<img src="image/logo.gif" alt="Logo" height="50" width="200" />
		<h2>A place to fly with turtles!</h2>
	</div>
	<!-- nav.php -->
	<ul id="nav">
		<li><a href="about/index.php">About</a></li>
		<li><a href="blog/index.php">Blog</a></li>
		<li><a href="contact/index.php">Contact</a></li>
	</ul>

	<div id="main">
		<!-- Main content goes here -->
	</div>

	<!-- footer.php -->
	<div id="footer"><p>Copyright 2010</p></div>
</body>
</html>

Looks just like a normal .html file, but it was created from smaller files at the moment we requested it from the server! You can use this simple method to abstract out just about anything from your pages, including the <head> information if you so choose. Other pages can be created using the index.php file as a template (and replacing the content in the main div) or by using an Ajax request to dynamically load new files into the main div. If you choose to create the files individually, I recommend creating a new subdirectory and index.php for each subpage. This with allow you to link people directly to subpages (http://www.yourdomain.com/about) without having to explain what a .php file is.

Remember that the goal here is to reduce redundancy and allow for maximum flexibility. That being said, you must decide for yourself which sections of your site are best to separate out and which you are going to want to customize for each page. Reusing the same meta information for every page on your site may save you some time, but you lose the ability to adjust your keywords and page titles to optimize your search engine placement.

Using the Google Font Directory

The Google Font Directory (or Google WebFonts) is an extremely simple way for developers and designers to expand their repertoire of available fonts. Typography on the web is usually restricted by the short list of Common Websafe Fonts that are available (or nearly equivalent) on all platforms. The only solution for many years was to use images, but this decreases readability for search engines and web crawlers, and can add significant loading time for your site.

Modern browsers are beginning to accept a variety of ways to import outside fonts, but the easiest and most universal way at this time is Google WebFonts. By going to the directory and selecting the font you’d like you use, Google will give you a link to a remote stylesheet (hosted by their servers), and then all you have to do is use it. Let’s take a look:

<!doctype html>
<html>
<head>
	<title>Checking out Google WebFonts</title>
	<link href="http://fonts.googleapis.com/css?family=Droid+Sans"
		rel="stylesheet" type="text/css" />
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>

	<h1>Check out this headline!</h1>
	<p>This will just be normal text</p>

</body>
</html>

You can see that in the <head> we have loaded two external stylesheets. The first is from the Google Font API which will have the browser load and initialize the use of your desired font, and the second is your own stylesheet for the site. Inside your stylesheet all you have to add is:

h1 {
	font-family: 'Droid Sans', Helvetica, Arial, sans-serif;
}

That’s it! Anytime you want to use this font all you have to do is change the font-family declaration. You’ll notice that I’ve included several fallback fonts for older browsers that don’t support WebFonts. It’s always important to degrade gracefully for your older users, although it is becoming less of a concern as even Microsoft is starting to catch up with the technology. Remember, because you’re using actual text instead of an image you can apply all the CSS you want to customize your look. Try some other neat CSS3 like text-shadow for a really modern look!

h1 {
	font-family: 'Droid Sans', Helvetica, Arial, sans-serif;
	font-size: 3em;
	letter-spacing: -1px;
	-moz-text-shadow: 2px 2px 3px #CCC;
	-webkit-text-shadow: 2px 2px 3px #CCC;
	text-shadow: 2px 2px 3px #CCC;
}

Google Font Directory Example

Head over to the Google Font Directory to try it out yourself!