<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bavotasan.com</title>
	<atom:link href="http://bavotasan.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bavotasan.com</link>
	<description>by c.bavota</description>
	<lastBuildDate>Wed, 08 Sep 2010 13:55:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Developing Themes for WordPress: Part 5</title>
		<link>http://bavotasan.com/tutorials/developing-themes-for-wordpress-make-money/</link>
		<comments>http://bavotasan.com/tutorials/developing-themes-for-wordpress-make-money/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 15:21:32 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Custom Themes]]></category>
		<category><![CDATA[customer support]]></category>
		<category><![CDATA[demos]]></category>
		<category><![CDATA[forums]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[make money]]></category>
		<category><![CDATA[translation ready]]></category>
		<category><![CDATA[WordPress themes]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2817</guid>
		<description><![CDATA[So far I have gone over a lot of the basic requirements for putting together a WordPress theme. Some stuff is pretty simple and other stuff might take a bit more time for you to wrap your head around. All in all, if you follow these tutorials you will be on the right track to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bavotasan.com/wp-content/uploads/2010/09/makemoney.jpg" alt="Make money selling themes" title="makemoney" width="200" height="150" class="alignright size-full wp-image-2821" />So far I have gone over a lot of the basic requirements for putting together a WordPress theme. Some stuff is pretty simple and other stuff might take a bit more time for you to wrap your head around. All in all, if you follow these tutorials you will be on the right track to completing your first customizable theme for WordPress. </p>
<p>During my WordCamp presentation, people asked me about getting their themes out there. I think the best way to discuss this is to tell you exactly how I did it, since it seemed to work for me.</p>
<p>I started working with WordPress about 5 years ago. I released my first free theme back in 2008. It was <a href="http://themes.bavotasan.com/our-themes/basic-themes/magazine-basic/">Magazine Basic</a>. I tried to develop a theme that had multiple easy-to-use options so users could configure it to their liking and could each create something unique. As of today, it has been downloaded 143,114 times from the WordPress.org theme directory. Within the first week of its release, it had so many downloads that I wanted to release another theme. So I did. </p>
<p>Before I knew it, I had a lot of requests for extra features, so I thought, &#8220;Why not see if I could sell some premium versions with as many extra features as possible?&#8221; Of course, I didn&#8217;t want to go overboard, so I developed some theme options that I thought would please a multitude of users. That&#8217;s when I started <a href="http://themes.bavotasan.com/">Themes by bavotasan.com</a>. </p>
<h3>Making Money</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/09/freethemes.jpg" alt="Premium themes" title="freethemes" width="550" height="183" class="alignleft size-full wp-image-2826" /><br />
There is no sure fire way to make money selling Premium WordPress Themes, but there are certain steps you can take that might help you cash in on the demand for high quality themes. Building a great theme and giving it away for free by including it in the WordPress.org directory is the first step into making a name for yourself in the community. People who use WordPress are very big on the fact that it&#8217;s free and open source. So give them something free and open source as well. </p>
<p>The better your theme, the more people will download it. Once your theme gets downloaded a few times, you will see that users will start to email you with questions about bugs, features they would like to see, and both positive and negative feedback on your work. These are all great things. The open discussion with your end user is invaluable. The information you gather will help point you in the right direction for how you should develop your theme on the next level: The Premium Theme level.</p>
<p>Premium Themes usually offer more control over every aspect of customization. They can have higher quality designs, multiple skins, different layouts and any other options you can imagine. Users expect something more from a Premium Theme and what better way to find out what that is exactly than by keeping an open communication with people that have already downloaded your free product?</p>
<p>Take a look at what other Premium Theme sites are offering by going to <a href="http://wordpress.org/extend/themes/commercial/">http://wordpress.org/extend/themes/commercial/</a>. That is the WordPress.org commercial theme listing page. Once you release your themes, getting your site listed on this page is a must. But you need to follow the guidelines from <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-part-1/">part 1</a> to a tee in order to qualify. Once you are listed on this page, people will check you out. Whether they buy your product or not will all depend on its quality and features.</p>
<h3>Translation Ready</h3>
<p>I had some questions about making your theme translation ready during my presentation, so that is obviously something that people are interested in. WordPress has a codex page dedicated to making your theme or plugin ready for internationalization. Read it at <a href="http://codex.wordpress.org/I18n_for_WordPress_Developers">http://codex.wordpress.org/I18n_for_WordPress_Developers</a>. Once you have prepared your files using the gettext libraries, you can create a .po file using this great online resource: <a href="http://www.icanlocalize.com/tools/php_scanner">http://www.icanlocalize.com/tools/php_scanner</a>. Create a <code>languages</code> folder in your theme and place your .po file in it. Then use the following code in your <code>functions.php</code> file:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Make theme available for translation</span>
<span style="color: #666666; font-style: italic;">// Translations can be filed in the /languages/ directory</span>
load_theme_textdomain<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'theme_name'</span><span style="color: #339933;">,</span> TEMPLATEPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/languages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$locale</span> <span style="color: #339933;">=</span> get_locale<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$locale_file</span> <span style="color: #339933;">=</span> TEMPLATEPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/languages/<span style="color: #006699; font-weight: bold;">$locale</span>.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_readable</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$locale_file</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$locale_file</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>Replace <code>theme_name</code> with the string you used in the gettext statements; it should be the name of your theme in lowercase with no spaces.</p>
<h3>Working Demos</h3>
<p>Putting together a demos site with the latest version of your themes allows users to test them out in a live environment. This is absolutely one of the best ways to promote your products. I am currently rebuilding my demo site using the WordPress 3.0 multi-site feature. Now each of my themes will be demoed on their own site, which means I can make sure that their greatest features are front and center, and I can customize my content to show where each theme stands out.</p>
<h3>Customer Support</h3>
<p>If you don&#8217;t support your themes, no one will want to use them because they won&#8217;t be able to rely on you for fixing bugs, upgrading as WordPress upgrades and day to day questions about how your theme works. Whether you do this through email, the WordPress.org forum or your own site, it doesn&#8217;t matter. Just as long as you do it. This help builds confidence in your users to try out other products you have developed. I spend a lot of time in my support forum responding to questions, and more often then not, things come up that I would have never thought of. Different ways to use my themes, simple features that might blow people away, or even just bugs that might only occur for 1% of my user base. I need to know this stuff. It helps to understand my customers, and in turn build better themes.</p>
<h3>Conclusion</h3>
<p>There are probably tons of things I might have missed along the way, but I think these tutorials will really get you moving in the right direction. If you have any questions, or feel like I didn&#8217;t go into enough detail about something, please let me know. I&#8217;ll do my best to keep things updated and will add in anything that you might think is necessary (or maybe I&#8217;ll save that for the book, <em>wink-wink</em>).</p>
<p>Part 1: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-part-1/">Guidelines for Developing a WordPress Theme</a><br />
Part 2: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-template-file/">Basic Template Files</a><br />
Part 3: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-the-loop/">Understand The WordPress Loop</a><br />
Part 4: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-options/">Adding Theme Options</a><br />
Part 5: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-make-money/">Making Money</a></p>
<div class="imgprov">
Protecting a good investment image by <a href="http://www.pixmac.com/author/arpad+nagy-bagoly%40ftl#cbavota">Arpad Nagy-Bagoly</a>, provided by <a href="http://www.pixmac.com#cbavota">Pixmac</a>.
</div>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/tutorials/developing-themes-for-wordpress-make-money/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Developing Themes for WordPress: Part 4</title>
		<link>http://bavotasan.com/tutorials/developing-themes-for-wordpress-options/</link>
		<comments>http://bavotasan.com/tutorials/developing-themes-for-wordpress-options/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 17:08:11 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[background editor]]></category>
		<category><![CDATA[custom menu]]></category>
		<category><![CDATA[Custom Themes]]></category>
		<category><![CDATA[featured image]]></category>
		<category><![CDATA[functions.php]]></category>
		<category><![CDATA[header image]]></category>
		<category><![CDATA[premium themes]]></category>
		<category><![CDATA[theme options]]></category>
		<category><![CDATA[twentyten]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2771</guid>
		<description><![CDATA[When you develop a theme for WordPress, you should consider giving your users a few customizable options so they can easily modify certain elements to their liking. Simple and easy-to-use controls are always the best, and now WordPress 3.0 makes it extremely easy to add features such as a custom menu, background color/image editor, featured [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bavotasan.com/wp-content/uploads/2010/09/options.jpg" alt="Theme Options" title="options" width="200" height="150" class="alignright size-full wp-image-2772" />When you develop a theme for WordPress, you should consider giving your users a few customizable options so they can easily modify certain elements to their liking. Simple and easy-to-use controls are always the best, and now WordPress 3.0 makes it extremely easy to add features such as a custom menu, background color/image editor, featured image selector and header images. All it takes is a few lines of code in your <code>functions.php</code> file and your theme will be up and running with some amazing options.</p>
<h3>Custom Menus</h3>
<p>Before WordPress 3.0, the only way to truly customize your menu was to do it manually. The default functions either allowed you to list categories, or pages, or links, but not all three together. And ordering them required a plugin. Now, all it takes is one simple function and the new menu system will be activated on your theme so users can customize their menus &#8217;til the cows come home.</p>
<p>To activate custom menus in your theme, add the following to your <code>functions.php</code> file:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_theme_support<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'nav-menus'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>NOTE:  Always make sure that when you add PHP to your <code>functions.php</code> file, it is included within the &lt;?php ?&gt; tags.</p>
<p>To really take control of the custom menus once you have activated them, you should also define some locations where they can be displayed.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">register_nav_menu<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'main'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Main Navigation Menu'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>The above registers a new menu location called &#8220;main.&#8221; When your users create a new menu, they can assign it to that location so it will be displayed on the front end. You can create as many theme locations as you wish so your users can place custom menus in multiple places.</p>
<div id="attachment_2775" class="wp-caption alignleft" style="width: 560px"><img src="http://bavotasan.com/wp-content/uploads/2010/09/menus.jpg" alt="Custom Menu System" title="menus" width="550" height="275" class="size-full wp-image-2775" /><p class="wp-caption-text">The new custom menu system in WordPress 3.0</p></div>
<p>Once you have registered a few menu locations, you need to actually add some code to your template files to display those menus. The following will display the &#8220;main&#8221; menu in the <code>header.php</code> file.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">wp_nav_menu<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'theme_location'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'main'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'sort_column'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'menu_order'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'container_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'main-navigation'</span>
<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>This will display the &#8220;main&#8221; menu if one has been assigned to that theme location. It will sort the menu according to how it is organized in the custom menu page, and it will surround it in a div container with the id &#8220;main-navigation.&#8221; There are many more parameters that can be set for this function. Check out <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">http://codex.wordpress.org/Function_Reference/wp_nav_menu</a> for more info.</p>
<h3>Background Editor</h3>
<p>This one is extremely easy to implement if you don&#8217;t plan on doing anything fancy with it. Add the following to functions.php to activate it:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_custom_background<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>This will add a link in the Appearance panel for Background. Clicking on that link will bring up the following screen:</p>
<div id="attachment_2780" class="wp-caption alignleft" style="width: 560px"><img src="http://bavotasan.com/wp-content/uploads/2010/09/background.jpg" alt="Backgroudn Editor" title="background" width="550" height="275" class="size-full wp-image-2780" /><p class="wp-caption-text">The new background editor in WordPress 3.0</p></div>
<p>Now your users can either select a color for their background, or add an image. If you want to design your theme with a default background, you&#8217;ll need to use the <code>add_custom_background()</code> function to set some callbacks to define your default background color or image.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_custom_background<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$header_callback</span><span style="color: #339933;">,</span> <span style="color: #000088;">$admin_header_callback</span><span style="color: #339933;">,</span> <span style="color: #000088;">$admin_image_div_callback</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>You can read more about the custom background callbacks in the codex at <a href="http://codex.wordpress.org/Function_Reference/add_custom_background">http://codex.wordpress.org/Function_Reference/add_custom_background</a>.</p>
<h3>The Featured Image</h3>
<p>This was actually a feature that was introduced in WordPress 2.9, but it&#8217;s one that I think all themes should take advantage of. Activating this option allows your users to select an image to represent their post. It doesn&#8217;t need to be inserted into their post or even in that specific post&#8217;s image gallery. </p>
<p>Activate it by adding this to your <code>functions.php</code> file:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_theme_support<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post-thumbnails'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'page'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>You can set whether it works with pages and posts, or just one or the other. Leaving the second parameter blank will automatically set it for all posts and pages. It will also set it for all custom post types that you might create.</p>
<p>Once the option is activated, a new panel will appear on the post/page edit screen with a link to set a featured image. This will just bring up the media upload screen and the option to use an image as a featured image will appear near the bottom.</p>
<p>There are also some cool additional functions you can use to set specific sizes for your image, in case your theme requires certain sized images for different areas.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">set_post_thumbnail_size<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_image_size<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'category-thumb'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// adding 'true' as a final parameter crops the image to those exact dimensions</span></pre></div></td></tr></table></div>

<p>The first piece of code will lock in a thumbnail size for your theme. This means it won&#8217;t be able to be modified under the Media link in the WordPress admin settings. The second line creates a new defined image size named &#8220;category-thumb.&#8221; When users upload new images, any image size you add using <code>add_image_size()</code> will tell WordPress that a new image thumbnail needs to be created with those dimensions.</p>
<p>To display the featured image in one of your theme templates requires the use of this function, and it must be placed within the loop:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'has_post_thumbnail'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> has_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    the_post_thumbnail<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'category-thumb'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'alignleft'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>The above code will fetch the &#8216;category-thumb&#8217; image if one exists for that post, set its class to &#8216;alignleft&#8217; and display it. Outside of the loop, you would have to use <code>get_the_post_thumbnail($post->ID, $name, $attr)</code>.</p>
<p>Read more about it at <a href="http://codex.wordpress.org/Function_Reference/the_post_thumbnail">http://codex.wordpress.org/Function_Reference/the_post_thumbnail</a>.</p>
<h3>The Header Image</h3>
<p>If you take a look at TwentyTen, you can see how this option can make it extremely easy for your users to add a custom image to the header of your theme. If you don&#8217;t plan on designing your theme with a large header image, you can still use this option to allow them to add a logo to their header. This one gets a little complex so it might be best to just point you toward the codex: </p>
<p><a href="http://codex.wordpress.org/Function_Reference/add_custom_image_header">http://codex.wordpress.org/Function_Reference/add_custom_image_header</a></p>
<h3>Part 5: The Other Stuff</h3>
<p>There is a lot more that you can add to your theme and tomorrow I am going to focus on the few things that people asked me about during my WordCamp presentation.</p>
<p>Part 1: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-part-1/">Guidelines for Developing a WordPress Theme</a><br />
Part 2: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-template-file/">Basic Template Files</a><br />
Part 3: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-the-loop/">Understand The WordPress Loop</a><br />
Part 4: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-options/">Adding Theme Options</a><br />
Part 5: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-make-money/">Making Money</a></p>
<div class="imgprov">
Businessman choosing image by <a href="http://www.pixmac.com/author/tombaky%40ftl#cbavota">Tombaky</a>, provided by <a href="http://www.pixmac.com#cbavota">Pixmac</a>.
</div>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/tutorials/developing-themes-for-wordpress-options/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Developing Themes for WordPress: Part 3</title>
		<link>http://bavotasan.com/tutorials/developing-themes-for-wordpress-the-loop/</link>
		<comments>http://bavotasan.com/tutorials/developing-themes-for-wordpress-the-loop/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 15:18:50 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[custom theme]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[the loop]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress 3.0]]></category>
		<category><![CDATA[Wordpress loop]]></category>
		<category><![CDATA[wp_query]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2757</guid>
		<description><![CDATA[If you&#8217;ve already gone through the first two parts of this series, you are well on your way to putting together a WordPress theme. It might seem a little daunting at first, but reading through these tutorials one by one and taking the time to understand it all will give you everything you need to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bavotasan.com/wp-content/uploads/2010/09/theloop.jpg" alt="The WordPress Loop" title="theloop" width="200" height="150" class="alignright size-full wp-image-2767" />If you&#8217;ve already gone through the first two parts of this series, you are well on your way to putting together a WordPress theme. It might seem a little daunting at first, but reading through these tutorials one by one and taking the time to understand it all will give you everything you need to create a WordPress theme to share with the community.</p>
<p>The WordPress loop is where all the magic happens. Understanding how it works will definitely make things a lot easier, because if you can&#8217;t wrap your head around the loop, it might just throw you for one (my wife loves a good pun so I wanted to add that in for her). I actually didn&#8217;t discuss the loop in my WordCamp presentation because I thought it was a topic all in itself. So this one is kind of a bonus.</p>
<h3>The WordPress Loop</h3>
<p>You&#8217;ve probably gone through a tutorial and reached a point where it told you to &#8220;add it to the loop,&#8221; and you thought to yourself, &#8220;What the hell&#8217;s a loop?&#8221; In WordPress, the loop is the database call that checks for posts and displays them if they exist. Certain functions will only work within the loop because they require certain variables to be set and those variables only exist within the loop, where all the post information is stored. </p>
<p>If you open up the <code>single.php</code> file from a theme, you&#8217;ll see something like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;div class=&quot;post&quot; id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
		&lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
		&lt;div class=&quot;thedate&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date_format'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
		&lt;div class=&quot;entry&quot;&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_tags<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;p class=&quot;tags&quot;&gt;&lt;small&gt;Tags: '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/small&gt;&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;p class=&quot;postmetadata alt&quot;&gt;
				&lt;small&gt;
					<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This entry was posted on '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>the_time<span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date_format'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>_e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' at '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>the_time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>_e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' and is filed under '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>the_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'. '</span><span style="color: #339933;">;</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You can follow any responses to this entry through the '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>post_comments_feed_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'RSS 2.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>_e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' feed.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
				&lt;/small&gt;
			&lt;/p&gt;
		&lt;/div&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_link_pages<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;p&gt;&lt;strong&gt;'</span><span style="color: #339933;">.</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/strong&gt; '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'next_or_number'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/div&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> comments_template<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Sorry, no posts matched your criteria.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>That is an example of a typical loop in a WordPress theme. It works by querying the database to fetch all the post&#8217;s stored information. That information becomes accessible by using WordPress functions within the loop to display certain elements wherever you want. On the single post page, only one post is queried. On category pages, multiple posts are queried and looped through.</p>
<p>Breaking down the loop to its basic elements would look something like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
     Do something here.
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
     Sorry, no posts matched your criteria.
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>All it means is this: IF you have posts, continue. WHILE you still have posts, loop through them all, then stop. ELSE there are no posts, display a message saying there are no posts. The actual loop is within the WHILE statement, since that is actually where it will loop through all the post and fetch their data.</p>
<p>As you can see, the loop is pretty important, and that&#8217;s why you&#8217;ll find it in all of the following basic template files:</p>
<ul>
<li>archive.php (used for categories, tags and archives)</li>
<li>index.php (what you want to appear on your front page)</li>
<li>page.php (how your pages will be displayed)</li>
<li>search.php (how your search page will be displayed)</li>
<li>single.php (how your posts will be displayed)</li>
</ul>
<p>The easiest way to develop these basic template files is to copy them over from a theme like TwentyTen, and customize them to work with your theme. This is not considered stealing, by the way, since the WordPress community is open source. That means the code is there for you to use and modify as you see fit. If you don&#8217;t modify it at all though, you better give credit where credit is due.</p>
<h3>The Loop in WordPress 3.0</h3>
<p>With the release of WordPress 3.0, a new file was introduced that allows you to store your loop(s) in one place. Using the new <code>loop.php</code> file is not a requirement, but it does make things a lot easier. If you take a look at the <code>single.php</code> above once again, you&#8217;ll see how it looks with the loop included in the file. Now see how we can simplify it by using the new <code>loop.php</code> file:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> get_template_part<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'loop'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'single'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>Now we can add our loop into <code>loop.php</code> and it would look something like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Sorry, no posts matched your criteria.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;div class=&quot;post&quot; id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
		&lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
		&lt;div class=&quot;thedate&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date_format'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
		&lt;div class=&quot;entry&quot;&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_tags<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;p class=&quot;tags&quot;&gt;&lt;small&gt;Tags: '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/small&gt;&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;p class=&quot;postmetadata alt&quot;&gt;
				&lt;small&gt;
					<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This entry was posted on '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>the_time<span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date_format'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>_e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' at '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>the_time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>_e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' and is filed under '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>the_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'. '</span><span style="color: #339933;">;</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You can follow any responses to this entry through the '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>post_comments_feed_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'RSS 2.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>_e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' feed.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
				&lt;/small&gt;
			&lt;/p&gt;
		&lt;/div&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_link_pages<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;p&gt;&lt;strong&gt;'</span><span style="color: #339933;">.</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/strong&gt; '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'next_or_number'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/div&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> comments_template<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>It might seem like you&#8217;ve just divided your code into two files, which you have, but now that loop can also be accessed by other template files. The advantage is plain to see: one loop can control your whole theme. Especially if you want to get fancy and use <a href="http://codex.wordpress.org/Conditional_Tags">conditional tags</a> to let your loop know what to display and when to display it. Adding a <a href="http://codex.wordpress.org/Conditional_Tags">conditional tag</a> to the content function would allow you to show the content only on single post pages, and the excerpt on all other pages:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> the_excerpt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>Call the loop in your <code>index.php</code> file using:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> get_template_part<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'loop'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'index'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>On your index page you will get the excerpt instead of the content. You can go as far as you want with <a href="http://codex.wordpress.org/Conditional_Tags">conditional tags</a> in your main loop. This will make it easier to modify your code and control how your post elements will be displayed within your theme. Take a look at <code>loop.php</code> in TwentyTen to see how much you can do with just one loop.</p>
<h3>Multiple Loops</h3>
<p>There may come a time when you want to have multiple loops in one template file. This might be a necessity for your theme if you&#8217;re developing a grid style layout for your front page, or want to have a listing of recent posts somewhere. You should never have two regular loops running on the same page because it will cause problems. That&#8217;s why WordPress has the <code>wp_query()</code> function.</p>
<p><code>wp_query()</code> allows you to have as many loops as you wish on a single page, since each of those loops will be self-contained with a custom query, using custom variables. The easiest way of explaining it is by showing it.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$featuredPosts</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$featuredPosts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'posts_per_page=5&amp;cat=1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$featuredPosts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">have_posts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$featuredPosts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">the_post</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #666666; font-style: italic;">// add stuff here</span>
<span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>That&#8217;s a self-contained custom loop that will not conflict with your main loop. If by chance, things do get a little funky, you can always reset the page&#8217;s main loop query by using:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_reset_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>You can find more information on the custom loop query in the codex at <a href="http://codex.wordpress.org/Function_Reference/WP_Query">http://codex.wordpress.org/Function_Reference/WP_Query</a>.</p>
<h3>What&#8217;s New with 3.0</h3>
<p>WordPress 3.0 introduced some new features that make it easier for theme developers to add amazing functionality to their themes without much effort. Check back tomorrow for more on that subject.</p>
<p>Part 1: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-part-1/">Guidelines for Developing a WordPress Theme</a><br />
Part 2: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-template-file/">Basic Template Files</a><br />
Part 3: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-the-loop/">Understand The WordPress Loop</a><br />
Part 4: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-options/">Adding Theme Options</a><br />
Part 5: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-make-money/">Making Money</a></p>
<div class="imgprov">
Fruit Loops image by <a href="http://www.pixmac.com/author/webking%40dt#cbavota">Webking</a>, provided by <a href="http://www.pixmac.com#cbavota">Pixmac</a>, and modified slightly by <a href="http://bavotasan.com">c.bavota</a>.
</div>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/tutorials/developing-themes-for-wordpress-the-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing Themes for WordPress: Part 2</title>
		<link>http://bavotasan.com/tutorials/developing-themes-for-wordpress-template-file/</link>
		<comments>http://bavotasan.com/tutorials/developing-themes-for-wordpress-template-file/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 15:19:01 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[footer]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[Sidebar]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[widgetized]]></category>
		<category><![CDATA[Widgets]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2720</guid>
		<description><![CDATA[In my last post, I tried to point you to the most important pages in the WordPress codex to get you moving in the right direction with developing your theme. Now I want to talk to you about the template files you&#8217;re going to need to put in place to make your theme work with [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bavotasan.com/wp-content/uploads/2010/08/keyboardkeys.jpg" alt="Computer keys from Pixmac" title="keyboardkeys" width="200" height="150" class="alignright size-full wp-image-2733" />In my last post, I tried to point you to the most important pages in the WordPress codex to get you moving in the right direction with developing your theme. Now I want to talk to you about the template files you&#8217;re going to need to put in place to make your theme work with WordPress.</p>
<h3>The Basic Theme</h3>
<p>Here is a list of the basic template files you need to get your theme working with WordPress:</p>
<ul>
<li>archive.php (used for categories, tags and archives)</li>
<li>comments.php (controls all your comments)</li>
<li>footer.php (elements you want to include in your theme’s footer)</li>
<li>functions.php (all your fancy functions)</li>
<li>header.php (elements required in a site’s header)</li>
<li>index.php (what you want to appear on your front page)</li>
<li>page.php (how your pages will be displayed)</li>
<li>search.php (how your search page will be displayed)</li>
<li>sidebar.php (what appears in your sidebar, must be widgetized)</li>
<li>single.php (how your posts will be displayed)</li>
</ul>
<p>In addition to these files, you also need the following:</p>
<ul>
<li>style.css (all your CSS and theme info)</li>
<li>screenshot.png (an image representing your theme)</li>
</ul>
<p>There are many more types of template files that you can add to your theme but the ones above are what I consider to be the bare minimum. You can read up on template files and the hierarchy used by WordPress at <a href="http://codex.wordpress.org/Template_Hierarchy">http://codex.wordpress.org/Template_Hierarchy</a>.</p>
<h3>The Stylesheet</h3>
<p>In order to design a theme for WordPress, you need to add some styling through a CSS file. That&#8217;s a given. But you also need to add a few more things to your <code>style.css</code> in order to get you theme working properly.</p>
<p>The following code must be added to the top of the <code>style.css</code> file:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
Theme Name: Twenty Ten
Theme URI: http://wordpress.org/
Description: The 2010 default theme for WordPress.
Author: the WordPress team
Author URI: http://wordpress.org/
Version: 1.0
Tags: black, blue, white, two-columns, fixed-width, custom-header, theme-options, threaded-comments, sticky-post, translation-ready, microformats, rtl-language-support, editor-style
&nbsp;
	The CSS, XHTML and design is released under GPL:
	http://www.opensource.org/licenses/gpl-license.php
&nbsp;
*/</span></pre></div></td></tr></table></div>

<p>This is the description and information that is relevant to your theme. The above was taken from TwentyTen. The last section refers to the GPL license. If you don&#8217;t wish to include your license here, you will have to include a <code>license.txt</code> file to explain which license you are using for your theme. If you want to be compatible with WordPress (since you are building a WordPress theme) you will need to follow the same GPL license. So either include a small line in your <code>style.css</code> file or copy over the <code>license.txt</code> from TwentyTen and include it in your theme folder.</p>
<p>If you wish to include your theme in the WordPress.org theme directory, there are only certain tags that are allowed. A list is available at <a href="http://wordpress.org/extend/themes/about/">http://wordpress.org/extend/themes/about/</a>. Including extra tags will make your theme fail the upload process on WordPress.org.</p>
<h3>The Screenshot</h3>
<p>People need to know what your theme looks like. That&#8217;s why a screenshot is required. Your screenshot must be a .PNG file and should be 300px by 225px. If you click on your Themes link under the Appearance panel in your wp-admin, you will see all the screenshots of the themes you have installed.</p>
<div id="attachment_2722" class="wp-caption alignnone" style="width: 310px"><img src="http://bavotasan.com/wp-content/uploads/2010/08/screenshot.png" alt="" title="screenshot" width="300" height="225" class="size-full wp-image-2722" /><p class="wp-caption-text">screenshot.png used in Magazine Basic</p></div>
<h3>The Header</h3>
<p>The <code>header.php</code> file contains everything that you want to appear at the top of your site. A lot of this at your discretion, but some is a must. If you plan on developing a theme for HTML5, this is how your <code>header.php</code> file should start:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html <span style="color: #000000; font-weight: bold;">&lt;?php</span> language_attributes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;
&lt;head&gt;
&lt;meta charset=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'charset'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;
&lt;link rel=&quot;profile&quot; href=&quot;http://gmpg.org/xfn/11&quot; /&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'stylesheet_url'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;link rel=&quot;pingback&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'pingback_url'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_singular<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> get_option<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'thread_comments'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> wp_enqueue_script<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'comment-reply'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_head<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/head&gt;</pre></div></td></tr></table></div>

<p>I develop my themes using the xHTML standards, since HTML5 is not fully integrated into most browsers just yet.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; <span style="color: #000000; font-weight: bold;">&lt;?php</span> language_attributes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;
&nbsp;
&lt;head profile=&quot;http://gmpg.org/xfn/11&quot;&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html_type'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>; charset= <span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'charset'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&nbsp;
&lt;title&gt; <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;
&nbsp;
&lt;link rel=&quot;stylesheet&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;link rel=&quot;pingback&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pingback_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_singular<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> get_option<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'thread_comments'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> wp_enqueue_script<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'comment-reply'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_head<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/head&gt;
&lt;body&gt;</pre></div></td></tr></table></div>

<p>The most important function in your <code>header.php</code> file is <code>wp_head()</code>. The little function will make many plugins and action hooks work with your theme. Without it, your theme would be somewhat useless.</p>
<h3>The Footer</h3>
<p>Your site&#8217;s footer is usually where you include a copyright notice. You might also want to repeat your menu or include some links. You could even widgetize your footer (I&#8217;ll talk about this later). That is entirely up to you. But you must have some things in place just like in your header. Your <code>footer.php</code> file must include the following:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/body&gt;
&lt;/html&gt;</pre></div></td></tr></table></div>

<p>The <code>wp_footer()</code> function is just like <code>wp_head()</code>. It makes your theme compatible with plugins and action hooks that rely on that specific function. </p>
<h3>The Sidebar</h3>
<p>You can set up as many sidebars as you like; TwentyTen has 8. To get started, let&#8217;s just focus on getting one sidebar working properly. One of WordPress&#8217;s greatest features is widgets. There are many useful default widgets that come bundled with WordPress, and there are an infinite number of plugins out there that give you even more widgets to play with.</p>
<div id="attachment_2728" class="wp-caption aligncenter" style="width: 570px"><a href="http://bavotasan.com/wp-content/uploads/2010/08/widgets.jpg" class="highslide"><img src="http://bavotasan.com/wp-content/uploads/2010/08/widgets-570x391.jpg" alt="" title="widgets" width="560" height="384" class="size-medium wp-image-2728" /></a><p class="wp-caption-text">The wp-admin Widgets Screen</p></div>
<p>Without a widgetized sidebar, though, widgets have nowhere to go. Luckily, creating a widgetized area in WordPress is extremely simple. This is what your basic <code>sidebar.php</code> file should look like:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;sidebar&quot;&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sidebar One'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;</pre></div></td></tr></table></div>

<p>In order for it to work, you need to add a bit of code to your <code>functions.php</code> file.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
register_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Sidebar One'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'front_lower_sidebar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'This is your first widgetized sidebar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div id=&quot;%1$s&quot; class=&quot;side-widget %2$s&quot;&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h3&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h3&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>I think most of the parameters are self-explanatory. You don&#8217;t have to use them all unless you are like me and need as much control as possible. The only ones that are a must are <code>name</code> and <code>id</code>.</p>
<p>You can actually add widgetized areas anywhere throughout your theme. You just need to use <code>register_sidebar()</code> to create a widgetized area and then <code>dynamic_sidebar()</code> to display it. You can even set up default widgets or text that will only appear if no widgets have been added. That would look like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;sidebar&quot;&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Sidebar One&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		Place default stuff here
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;</pre></div></td></tr></table></div>

<h3>Part 3: What&#8217;s a loop?</h3>
<p>Since the WordPress loop is something that requires a lot of attention, I think it would be best to have a whole post dedicated to it. Look out for that coming up.</p>
<p>Part 1: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-part-1/">Guidelines for Developing a WordPress Theme</a><br />
Part 2: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-template-file/">Basic Template Files</a><br />
Part 3: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-the-loop/">Understand The WordPress Loop</a><br />
Part 4: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-options/">Adding Theme Options</a><br />
Part 5: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-make-money/">Making Money</a></p>
<div class="imgprov">
Keyboard Keys image by <a href="http://www.pixmac.com/author/janakadharmasena%40dt#cbavota">Janakadharmasena</a>, provided by <a href="http://bit.ly/dqbS5q">Pixmac</a>.
</div>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/tutorials/developing-themes-for-wordpress-template-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing Themes for WordPress: Part 1</title>
		<link>http://bavotasan.com/tutorials/developing-themes-for-wordpress-part-1/</link>
		<comments>http://bavotasan.com/tutorials/developing-themes-for-wordpress-part-1/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 21:19:36 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[codex]]></category>
		<category><![CDATA[premium themes]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2709</guid>
		<description><![CDATA[Over the weekend, I gave a presentation on developing WordPress themes for fun and profit. It went really well and I thought it would be a good idea to go into a bit more detail on everything I mentioned so that people can have a point of reference. I began my presentation with the new [...]]]></description>
			<content:encoded><![CDATA[<p>Over the weekend, I gave a presentation on developing WordPress themes for fun and profit. It went really well and I thought it would be a good idea to go into a bit more detail on everything I mentioned so that people can have a point of reference. I began my presentation with the new guidelines that are still being set up on WordPress.org and that is what the first part of this series will focus on.</p>
<h3>WordPress 3.0 Changes Everything</h3>
<p>With the release of WP 3.0, the &#8220;official&#8221; theme reviewer(s) on WordPress.org thought it would be a good idea to improve the current requirements and come up with a strict guideline to let theme developers know exactly what is expected of their themes. This would make the job of reviewing themes for WordPress.org much easier, but it would also set a standard for all the themes within the WP Themes Directory, and hopefully, all WP themes in general.</p>
<p>As a developer, the more documentation you can get about the software you are developing for, the easier your job is. And now WordPress has three pages in the codex dedicated to theme development that all developers need to read and understand.</p>
<h3>The Theme Unit Test</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/08/themeunit.jpg" alt="Theme Unit Test" title="themeunit" width="550" height="160" class="alignleft size-full wp-image-2710" /><br />
The theme unit test is an xml file that a developer should use in their testing environment. If you do not have a test install of WordPress to test your themes, that is the first step you should take. Once you have you test install up and running, download the theme unit test xml file and upload it into your WP install by going to the Tools panel in your wp-admin and clicking on the Import link. Import the xml file and all of the images associated with it. Now you have a test blog full of content that will help you make sure that your theme works with the many different features of WordPress.</p>
<p>The codex page lists all the different types of content that is uploaded by the xml file, and how is should be displayed by your theme. If things don&#8217;t look right on your theme, then you need to make sure to follow the guidelines and include the proper functions and/or CSS to get it looking the way it should.</p>
<p>Codex page: <a href="http://codex.wordpress.org/Theme_Unit_Test">http://codex.wordpress.org/Theme_Unit_Test</a></p>
<h3>Theme Development Guidelines</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/08/themedevelopment.jpg" alt="Theme Development Guidelines" title="themedevelopment" width="550" height="160" class="alignleft size-full wp-image-2712" /><br />
The title of this codex page pretty much says it all. These are the guidelines for developing a WordPress theme. There are many things that need to be in place in order for your theme to work with  WP. If your theme does not conform to these requirements, it will not work with WordPress. That&#8217;s why this part of the codex is the most important piece of documentation for any theme developer.</p>
<p>Reading through the guidelines will put you on the right track in regards to how your theme should be structured, what functions are a <em>must</em>, and what files need to be included in order for it to work properly. The page is quite long, but once you get trough it and start to piece together your theme, you&#8217;ll realize that it isn&#8217;t as hard as it seems. And remember, all well-built WordPress themes follow these guidelines, so just take a look behind the scenes of one of your favorite themes to see how the code has been implemented if you feel you&#8217;re stuck. </p>
<p>Codex page: <a href="http://codex.wordpress.org/Theme_Development">http://codex.wordpress.org/Theme_Development</a></p>
<h3>Theme Review Process</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/08/themereview.jpg" alt="Theme Review Process" title="themereview" width="550" height="160" class="alignleft size-full wp-image-2711" /><br />
This page describes exactly how your theme will be scrutinized if you submit it to the WordPress.org Theme Directory. Knowing exactly what the theme reviewers look at and using that information to personally judge your own theme will help guarantee that you have developed a theme that is up to snuff. It also lets you know some of the dos and don&#8217;ts that you should be aware of that were not discussed on the other two codex pages.</p>
<p>Codex page: <a href="http://codex.wordpress.org/Theme_Review">http://codex.wordpress.org/Theme_Review</a></p>
<h3>Part 2: What goes where?</h3>
<p>Next I will discuss what basic templates files are necessary for your theme and what code is required in order to get everything working properly.</p>
<p>Part 1: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-part-1/">Guidelines for Developing a WordPress Theme</a><br />
Part 2: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-template-file/">Basic Template Files</a><br />
Part 3: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-the-loop/">Understand The WordPress Loop</a><br />
Part 4: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-options/">Adding Theme Options</a><br />
Part 5: <a href="http://bavotasan.com/tutorials/developing-themes-for-wordpress-make-money/">Making Money</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/tutorials/developing-themes-for-wordpress-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimization Tips to Speed Up Your Site</title>
		<link>http://bavotasan.com/tutorials/optimization-tips-speed-up-site/</link>
		<comments>http://bavotasan.com/tutorials/optimization-tips-speed-up-site/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 21:14:56 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[compress]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[etags]]></category>
		<category><![CDATA[expired headers]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[minify]]></category>
		<category><![CDATA[mod_deflate]]></category>
		<category><![CDATA[mod_gzip]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[smush.it]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[web site]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2682</guid>
		<description><![CDATA[Ever since Google announced that a site&#8217;s speed would be a major factor in its ranking, I have really been paying attention to how my site performs. I guess I should have been doing it anyway, but I am the type of person that sometimes needs a kick in the butt to realize what he [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since <a href="http://googlewebmastercentral.blogspot.com/2010/04/using-site-speed-in-web-search-ranking.html">Google announced</a> that a site&#8217;s speed would be a major factor in its ranking, I have really been paying attention to how my site performs. I guess I should have been doing it anyway, but I am the type of person that sometimes needs a kick in the butt to realize what he should be doing. Now I keep an eye on my site and constantly monitor how it&#8217;s performing. That&#8217;s the only way to stay on top of things and guarantee that your visitors have a positive experience on your site.</p>
<p>Many things factor in to how your site performs, including the speed of your server, the amount of traffic on your site, how your site is coded, if your site is static or dynamic, and the list goes on. If your site has not been optimized then you are really doing yourself a disservice, especially now that your page rank might rely on it.</p>
<p>If you have a WordPress site, there are some great plugins to help you out. I like to use <a href="http://wordpress.org/extend/plugins/wp-super-cache/">WP Super Cache</a> to get things started. It is pretty easy to set up and works exceptionally well. Plus, the customer support is top notch, so if you have any issues you can just contact the author.</p>
<p>If you don&#8217;t use WordPress, you can still follow some of the steps below to get your site performing at its best.</p>
<p>First, let&#8217;s take a look at some free tools that are available online that can analyze your site and let you know exactly where the problems lie:</p>
<h3>Pingdom Tools</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/08/pingdomtools.jpg" alt="Pingdom Tools" title="pingdomtools" width="550" height="160" class="alignleft size-full wp-image-2681" /><br />
Pingdom Tools will give you a breakdown of all the files that your site needs to load to render a page, and whether or not any of them is problematic. It can also save your tests so you can compare your site&#8217;s statistics against one another on different occasions.<br />
<a href="http://tools.pingdom.com/">http://tools.pingdom.com/</a></p>
<h3>Web Page Test</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/08/webpagetest.jpg" alt="Web Page Test" title="webpagetest" width="550" height="160" class="alignleft size-full wp-image-2686" /><br />
Web Page Test provides a similar service to Pingdom Tools, but the results are a lot more elaborate. The test takes a bit longer but it&#8217;s well worth the wait. Your site will be graded on 6 different aspects of its performance: KeepAlive Enabled, Compress Text, Compress Images, Cache Static Content, Combine CSS/JS Files and Use of CDN. Once you are graded, you will also see why your site might have failed each test.<br />
<a href="http://www.webpagetest.org/">http://www.webpagetest.org/</a></p>
<h3>Firebug &#038; YSlow</h3>
<p><img src="http://bavotasan.com/wp-content/uploads/2010/08/firebug.jpg" alt="Firebug for Firefox" title="firebug" width="550" height="160" class="alignleft size-full wp-image-2687" /><br />
If you have a Web site and you&#8217;re not aware of Firebug, you need to become aware of it immediately. It&#8217;s an amazing developer tool for Firefox that can make your life a hell of a lot easier. It offers tools such as an element inspector, CSS editor, and  process console. To get your site optimized, install YSlow from Yahoo and you will have all the tools you need to test your site and find its weaknesses.<br />
<a href="http://getfirebug.com/">http://getfirebug.com/</a><br />
<a href="http://developer.yahoo.com/yslow/">http://developer.yahoo.com/yslow/</a></p>
<p>Once you&#8217;ve tested your site and you know what the problems are, you can start to make a few changes to help increase your site&#8217;s performance, which will in turn give your visitors a better experience and show search engines that you mean business.</p>
<p>You probably already know these tips, but just in case you don&#8217;t, pay attention because they are the basis of how you can optimize your site:</p>
<h3>Optimize Images for the Web</h3>
<p>If you plan on uploading an image to your site, make sure you&#8217;re not uploading the original 5 x 7 that has a resolution of 300dpi. Why? Because it&#8217;s such a large file that it will definitely slow down your site, if not crash it. That&#8217;s why all images must be optimized for the Web. If you have Photoshop, or any image editing software, you&#8217;ll have the option to export your image for the Web. </p>
<p>What does that mean? Well, first of all, you should probably aim for 72dpi, which is pretty much the Web standard. That will help bring your file size down. You should also save your photos as JPGs with a quality of around 50-60%, and your graphics as GIFs with a color range dependent on the graphic itself. If your image has a transparent background which doesn&#8217;t look too good as a transparent GIF, then you might want to make it a transparent PNG. That does increase the size of the file, so keep that in mind.</p>
<p>If you want to really get fancy, you can put together a CSS sprite so that all of your graphics and images are merged together into one file. This brings down the number of elements that your site has to load, but it does require a bit more effort in regards to the CSS used. Here is a CSS sprite I use on <a href="http://bavotasan.com">bavotasan.com</a>:</p>
<p><img src="http://bavotasan.com/wp-content/themes/bavotasan-2010/images/sprite_bavotasan.png" alt="CSS Sprite or bavotasan.com" width="336" height="225" class="aligncenter"  /></p>
<p>If you don&#8217;t have any desktop software to optimize your images, you can always take advantage of <a href="http://www.smushit.com/ysmush.it/">Yahoo&#8217;s Smush.it</a>, which allows you to upload an image file and have it optimized and returned to you. If you have YSlow installed, then you also have Smush.it included on the tools tab.</p>
<h3>Put CSS at the Top &#038; JavaScript at the Bottom</h3>
<p>Placing your CSS at the top of your site makes sense, because you want to have your elements styled before they start to render. Placing JavaScript at the bottom also makes a lot of sense because you need your elements to render before they can be manipulated by your JavaScript. This has become a standard and should always be the way these files are included in your site.</p>
<h3>Reduce the Number of HTTP Requests</h3>
<p>An HTTP request occurs every time your site fetches a file that is required to render the page. So every image, every JS file and pretty much every element on your Web page requires an HTTP request. That&#8217;s why CSS sprites are a great idea. They reduce the number of times your site needs to fetch an image. Another great idea is combining your CSS files and your JavaScript files into one. So grab all of your site&#8217;s CSS (you can view it using Firebug), create one file and include it in your header. Same goes for your JavaScript files, but make sure you place the JS elements in the proper order or else they won&#8217;t work, eg. jQuery needs to load before you use any actual jQuery. And be sure to stick your JS file in your footer.</p>
<p>If you don&#8217;t plan on making any changes to your CSS or JS, you can even minify the files to make them as small as possible. There are many online resources to do this, but you also have everything you need if you already installed Firebug and YSlow. If you take a look at <a href="http://jquery.com/">http://jquery.com/</a>, you can see the difference between the minified version (24kb) and the development version (155kb). That&#8217;s a big difference.</p>
<h3>The Hard Stuff</h3>
<p>This is where things start to get a little more complicated. The following tips require a bit of knowledge of coding, or at least a willingness to attempt to do some things that you might not really understand.</p>
<h3>Configure your ETags</h3>
<p>According to <a href="http://en.wikipedia.org/wiki/HTTP_ETag">Wikipedia</a>, an ETag, or entity tag, &#8220;<em>is one of several mechanisms that HTTP provides for cache validation, and which allows a client to make conditional requests.</em>&#8221; If you don&#8217;t plan on using them, which most likely you won&#8217;t, then you need to remove them completely by adding the following to your <code>.htaccess</code> file.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">FileETag none</pre></div></td></tr></table></div>

<p>If you don&#8217;t have an <code>.htaccess</code> file in your site&#8217;s root directory, then create one and upload it because you&#8217;re going to have to make a few modifications to it to get your site optimized.</p>
<h3>Add Expires Headers</h3>
<p>Expires headers will let everyone know that certain elements can be cached by the browser so they won&#8217;t need to be reloaded every time a visitor hits your site. Static elements should have a far future expiration date and dynamic elements need to be configured according to how you plan on using them. The following will add an expiration date of one month to all your image, CSS and JS files.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Expire images header
</span>ExpiresActive On
ExpiresDefault A0
ExpiresByType image<span style="color: #339933;">/</span>gif A2592000
ExpiresByType image<span style="color: #339933;">/</span>png A2592000
ExpiresByType image<span style="color: #339933;">/</span>jpg A2592000
ExpiresByType image<span style="color: #339933;">/</span>jpeg A2592000
ExpiresByType image<span style="color: #339933;">/</span>ico A2592000
ExpiresByType text<span style="color: #339933;">/</span>css A2592000
ExpiresByType text<span style="color: #339933;">/</span>javascript A2592000</pre></div></td></tr></table></div>

<p>A2592000 (60*60*24*30) is a timestamp that equals one month. Remember, if you plan on modifying any files that have been cached with a future expiration date, you  need to rename them or else visitors will not see the changes until they clear their browser cache or the old files expire.</p>
<h3>Compress Components</h3>
<p>Compressing things always ends up making them smaller and load faster, so implementing some form of compression on your components is a must. This optimization step might not work for you if your server does not have either mod_deflate or mod_gzip installed as part of Apache. You should contact your service provider and inquire about this to find out which of the following codes you should use.</p>
<p>mod_deflate:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>FilesMatch <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>.(js|css|html|htm|php|xml)$&quot;</span><span style="color: #339933;">&gt;</span>
SetOutputFilter DEFLATE
<span style="color: #339933;">&lt;/</span>FilesMatch<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>mod_gzip</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>IfModule mod_gzip<span style="color: #339933;">.</span>c<span style="color: #339933;">&gt;</span>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include <span style="color: #990000;">file</span> \<span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span>html?<span style="color: #339933;">|</span>txt<span style="color: #339933;">|</span>css<span style="color: #339933;">|</span>js<span style="color: #339933;">|</span>php<span style="color: #339933;">|</span>pl<span style="color: #009900;">&#41;</span>$
mod_gzip_item_include handler ^cgi<span style="color: #339933;">-</span>script$
mod_gzip_item_include mime ^text<span style="color: #339933;">/.*</span>
mod_gzip_item_include mime ^application<span style="color: #339933;">/</span>x<span style="color: #339933;">-</span>javascript<span style="color: #339933;">.*</span>
mod_gzip_item_exclude mime ^image<span style="color: #339933;">/.*</span>
mod_gzip_item_exclude rspheader ^Content<span style="color: #339933;">-</span>Encoding<span style="color: #339933;">:.*</span>gzip<span style="color: #339933;">.*</span>
<span style="color: #339933;">&lt;/</span>IfModule<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<h3>Content Delivery Network</h3>
<p>It&#8217;s a little hard to believe, but the closer your visitor is to your server&#8217;s location, the faster they will receive your site elements. That&#8217;s where a CDN can come in handy. They provide multiple server locations for your site elements that will be accessed accordingly depending on where you visitors are located. This has been known to improve your site&#8217;s response time by up to 20%. The only problem, is it might cost you an arm and a leg to get it up and running. There are many CDNs popping up that are not as expensive as others, but to tell you the truth, this might not be a viable option unless your site is really bringing in the money, which in turn would make it worth having a CDN on your side.</p>
<h3>Conclusion</h3>
<p>When it comes down to it, running a successful Web site requires a lot of attention to certain things that you might never have considered. Being aware of optimization tools and techniques will definitely help you improve your site&#8217;s performance. Most importantly, it will get your site ready to be indexed by Google, Yahoo and many other search engines that rely on speed as a ranking factor.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/tutorials/optimization-tips-speed-up-site/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create bit.ly Short URLs for your Posts in WordPress</title>
		<link>http://bavotasan.com/tutorials/create-bit-ly-short-urls-for-your-posts-in-wordpress/</link>
		<comments>http://bavotasan.com/tutorials/create-bit-ly-short-urls-for-your-posts-in-wordpress/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 18:48:00 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[functions.php]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[mods]]></category>
		<category><![CDATA[short urls]]></category>
		<category><![CDATA[shortlinks]]></category>
		<category><![CDATA[tweets]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2668</guid>
		<description><![CDATA[I have been working with the http://bit.ly API and decided to change the short URLs on my site to include the short URLs provided by http://bit.ly. The API is pretty straightforward and I created a few WordPress functions to to get it all working. Before we even start, you would need to registered with http://bit.ly [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working with the <a href="http://bit.ly/">http://bit.ly</a> API and decided to change the short URLs on my site to include the short URLs provided by <a href="http://bit.ly/">http://bit.ly</a>. The API is pretty straightforward and I created a few WordPress functions to to get it all working.</p>
<p>Before we even start, you would need to registered with <a href="http://bit.ly/">http://bit.ly</a> and then check out this page <a href="http://bit.ly/a/your_api_key">http://bit.ly/a/your_api_key</a> to get your API key and your login.</p>
<p>Now, let&#8217;s add a function to automatically create a <a href="http://bit.ly/">http://bit.ly</a> short URL when you publish a post. We will hook into the <code>publish_post</code> action and then use the <a href="http://bit.ly/">http://bit.ly</a> API to fetch a shortened URL. Place the following into your theme&#8217;s <code>function.php</code> file.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publish_post'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'create_bitly'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> create_bitly<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$login</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'YOUR LOGIN'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// change this to your login</span>
	<span style="color: #000088;">$apikey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'YOUR API KEY'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// change this to your API key</span>
&nbsp;
	<span style="color: #000088;">$longURL</span> <span style="color: #339933;">=</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// here we get the permalink to your post</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// This is the API call to fetch the shortened URL</span>
	<span style="color: #000088;">$apiurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://api.bit.ly/v3/shorten?longUrl='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$longURL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;login='</span><span style="color: #339933;">.</span><span style="color: #000088;">$login</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;apiKey='</span><span style="color: #339933;">.</span><span style="color: #000088;">$apikey</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// We are using cURL</span>
	<span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$apiurl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$shortURL</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$results</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// the short URL</span>
&nbsp;
	update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bitlyURL'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$shortURL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// adding the short URL to a custom field called bitlyURL</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>You can read more about the <a href="http://bit.ly/">http://bit.ly</a> API here: <a href="http://code.google.com/p/bitly-api/wiki/ApiDocumentation">http://code.google.com/p/bitly-api/wiki/ApiDocumentation</a></p>
<p>In order to add your new short URL to your header, you first need to remove the default shortlink tag and then create a function that will place the proper code between your <code>&lt;head&gt;</code> tags.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">remove_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wp_shortlink_wp_head'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// removing the default shortlink</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bilty_shortlink_head'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// adding the new bit.ly shortlink</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> bilty_shortlink_head<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$shortURL</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bitlyURL'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$shortURL</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;link rel=&quot;shortlink&quot; href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$shortURL</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; /&gt;'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;link rel=&quot;shortlink&quot; href=&quot;'</span><span style="color: #339933;">.</span>get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?p='</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; /&gt;'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>If you want to display your new short URLs, you can do so by using the `wp_get_shortlink()` function. But first you need to make sure that WordPress knows to replace the default short URL with the new <a href="http://bit.ly/">http://bit.ly</a> short URL.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pre_get_shortlink'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'get_bitly_shortlink'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// filtering the WP function</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> get_bitly_shortlink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$shortURL</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bitlyURL'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$shortURL</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$shortURL</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?p='</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>You can place the following code anywhere within the loop of your <code>single.php</code> theme file to display your short URL.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">Short URL: &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wp_get_shortlink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wp_get_shortlink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;</pre></div></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/tutorials/create-bit-ly-short-urls-for-your-posts-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Optimizing your MySQL Database</title>
		<link>http://bavotasan.com/tutorials/optimizing-your-mysql-database/</link>
		<comments>http://bavotasan.com/tutorials/optimizing-your-mysql-database/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 15:20:12 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqlcheck]]></category>
		<category><![CDATA[mysqltuner]]></category>
		<category><![CDATA[optimize mysql]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2658</guid>
		<description><![CDATA[I run my Web sites on a dedicated virtual server and every once in a while, I need to go in and optimize things to make sure everything runs smoothly. I am not an expert when it comes to shell commands, but do I know a few that really help keep things working the way [...]]]></description>
			<content:encoded><![CDATA[<p>I run my Web sites on a dedicated virtual server and every once in a while, I need to go in and optimize things to make sure everything runs smoothly. I am not an expert when it comes to shell commands, but do I know a few that really help keep things working the way they should. </p>
<p>One of the most important things I have come to realize is that you must keep an eye on your MySQL tables, because a problematic database can slow down your server dramatically. Databases that see a lot of queries often become fragmented and these are the databases that can start to cause you some problems. Luckily, there is a shell command that can go in and do all your de-fragmenting and optimizing for you.</p>
<p>I always make sure to back things up before I run this, just in case.</p>
<p>This command must be run from the shell and you need to be logged in as a root user:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="sql" style="font-family:monospace;">mysqlcheck <span style="color: #66cc66;">-</span>u root <span style="color: #66cc66;">-</span>p <span style="color: #808080; font-style: italic;">--auto-repair --check --optimize --all-databases</span></pre></div></td></tr></table></div>

<p>Once the command has been entered, you will need to input your password. Then you will see it list through your database tables one by one as it works it magic.</p>
<p>You can read up on the <a href="http://dev.mysql.com/doc/refman/5.0/en/mysqlcheck.html">mysqlcheck</a> command to understand exactly what it does.</p>
<p>Another worthwhile tool is <a href="http://blog.mysqltuner.com/">MySQLTuner</a>. It can help you with recommendations on how to configure your MySQL to increase performance and stability.  I use it every month too see if anything has been acting up and that is a good routine to get into to keep your sites running their best.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/tutorials/optimizing-your-mysql-database/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Draw a Smiley Face with CSS3</title>
		<link>http://bavotasan.com/tutorials/draw-smiley-face-css3/</link>
		<comments>http://bavotasan.com/tutorials/draw-smiley-face-css3/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 22:52:43 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[behold]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Circles]]></category>
		<category><![CDATA[course]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[deg]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[failed attempts]]></category>
		<category><![CDATA[ffe]]></category>
		<category><![CDATA[gradients]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[inset]]></category>
		<category><![CDATA[inspiration]]></category>
		<category><![CDATA[lefteye]]></category>
		<category><![CDATA[linear gradient]]></category>
		<category><![CDATA[ovals]]></category>
		<category><![CDATA[position]]></category>
		<category><![CDATA[power]]></category>
		<category><![CDATA[radius]]></category>
		<category><![CDATA[random shapes]]></category>
		<category><![CDATA[rgba]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[smile]]></category>
		<category><![CDATA[smiley face]]></category>
		<category><![CDATA[smileyface]]></category>
		<category><![CDATA[something]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2643</guid>
		<description><![CDATA[I was messing around with CSS3 gradients, rounded corners and shadows, and I thought to myself, &#8220;I wonder if I can draw something that actually looks like something?&#8221; Lo and behold, I could. I decided to go with a smiley face, since it would need circles, ovals and some random shapes. It would also require [...]]]></description>
			<content:encoded><![CDATA[<p>I was messing around with CSS3 gradients, rounded corners and shadows, and I thought to myself, &#8220;I wonder if I can draw something that actually looks like something?&#8221; Lo and behold, I could. I decided to go with a smiley face, since it would need circles, ovals and some random shapes. It would also require gradients and shadows. After a few failed attempts, I somehow managed to figure it out and the outcome is pretty cool.</p>
<div class="smileyface">
<p class="eyes lefteye">
<p class="eyes righteye">
<div class="smile">
<div class="corner"></div>
<div class="corner right"></div>
</p></div>
</div>
<p>It really amazes me that CSS3 has the power to create something like this. I tested it out in Firefox, Safari and Chrome. They all look good. Of course, in IE it looks like this&#8230;</p>
<p><a href="http://bavotasan.com/wp-content/uploads/2010/08/smileyie.jpg"><img src="http://bavotasan.com/wp-content/uploads/2010/08/smileyie.jpg" alt="" title="smileyie" width="300" height="300" class="nobox aligncenter size-full wp-image-2654" /></a></p>
<p>It&#8217;s like IE is living in 1986.</p>
<p>Here is the HTML:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;smileyface&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>p <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;eyes lefteye&quot;</span><span style="color: #339933;">&gt;&lt;/</span>p<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>p <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;eyes righteye&quot;</span><span style="color: #339933;">&gt;&lt;/</span>p<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;smile&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;corner&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;corner right&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>Here is the CSS:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.smileyface</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffe632</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> -webkit-gradient<span style="color: #00AA00;">&#40;</span>linear<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> from<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#fffe8d</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span> to<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#f6d23e</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> -moz-linear-gradient<span style="color: #00AA00;">&#40;</span><span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span>  <span style="color: #cc00cc;">#fffe8d</span><span style="color: #00AA00;">,</span>  <span style="color: #cc00cc;">#f6d23e</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>	
	box-shadow<span style="color: #00AA00;">:</span> <span style="color: #993333;">inset</span> <span style="color: #933;">0px</span> <span style="color: #933;">-14px</span> <span style="color: #933;">14px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> .3<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span> <span style="color: #933;">0px</span> <span style="color: #933;">2px</span> <span style="color: #933;">20px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> .6<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #993333;">inset</span> <span style="color: #933;">0px</span> <span style="color: #933;">-14px</span> <span style="color: #933;">14px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> .3<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span> <span style="color: #933;">0px</span> <span style="color: #933;">2px</span> <span style="color: #933;">20px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> .6<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #993333;">inset</span> <span style="color: #933;">0px</span> <span style="color: #933;">-14px</span> <span style="color: #933;">14px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> .3<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span> <span style="color: #933;">0px</span> <span style="color: #933;">2px</span> <span style="color: #933;">20px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> .6<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
p<span style="color: #6666ff;">.eyes</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">80px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#222</span><span style="color: #00AA00;">;</span>
	border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span>/<span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span> <span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span>/<span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
	box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #cc66cc;">0</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.8</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #cc66cc;">0</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.8</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #cc66cc;">0</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.8</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>	
&nbsp;
	p<span style="color: #6666ff;">.eyes</span><span style="color: #6666ff;">.lefteye</span> <span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">75px</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span>
&nbsp;
	p<span style="color: #6666ff;">.eyes</span><span style="color: #6666ff;">.righteye</span> <span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">75px</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span>
&nbsp;
div<span style="color: #6666ff;">.smile</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">70px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#222</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">120px</span> <span style="color: #933;">120px</span> / <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">90px</span> <span style="color: #933;">90px</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">120px</span> <span style="color: #933;">120px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">90px</span> <span style="color: #933;">90px</span><span style="color: #00AA00;">;</span>
	border-radius<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">120px</span> <span style="color: #933;">120px</span> / <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">90px</span> <span style="color: #933;">90px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">38px</span><span style="color: #00AA00;">;</span>
	box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #cc66cc;">0</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.8</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #cc66cc;">0</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.8</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #cc66cc;">0</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.8</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
div<span style="color: #6666ff;">.corner</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#222</span><span style="color: #00AA00;">;</span>
	border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span>/<span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span> <span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span>/<span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-12px</span><span style="color: #00AA00;">;</span>
	-webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>65deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	-moz-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>65deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-12px</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	div<span style="color: #6666ff;">.corner</span><span style="color: #6666ff;">.right</span> <span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">202px</span><span style="color: #00AA00;">;</span>
		-webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-65deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
		-moz-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-65deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>		
		<span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>Inspiration:</p>
<ul>
<li><a href="http://desandro.com/articles/opera-logo-css/">http://desandro.com/articles/opera-logo-css/</a></li>
<li><a href="http://cordobo.com/wp-content/uploads/ie-pure-css-logo/">http://cordobo.com/wp-content/uploads/ie-pure-css-logo/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/tutorials/draw-smiley-face-css3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Use jQuery to Replace a Word with a Link</title>
		<link>http://bavotasan.com/tutorials/jquery-replace-word-with-link/</link>
		<comments>http://bavotasan.com/tutorials/jquery-replace-word-with-link/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 20:54:46 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[body]]></category>
		<category><![CDATA[core function]]></category>
		<category><![CDATA[footer]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[ig]]></category>
		<category><![CDATA[instance]]></category>
		<category><![CDATA[javascript replace function]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Lt]]></category>
		<category><![CDATA[multiple times]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[piece]]></category>
		<category><![CDATA[posttop]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[slash]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[thePage]]></category>
		<category><![CDATA[var]]></category>
		<category><![CDATA[way]]></category>
		<category><![CDATA[Word]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=2615</guid>
		<description><![CDATA[If you use a word multiple times on your site and you don&#8217;t feel like going through all your posts to replace every instance of it, you can use jQuery to search your page and do the replacing for you. I wanted to replace a word throughout an entire site with a link and all [...]]]></description>
			<content:encoded><![CDATA[<p>If you use a word multiple times on your site and you don&#8217;t feel like going through all your posts to replace every instance of it, you can use jQuery to search your page and do the replacing for you. I wanted to replace a word throughout an entire site with a link and all it took was a small piece of code. </p>
<p>If you don&#8217;t already have jQuery loaded into your page, include this before your closing <code>&lt;head&gt;</code>.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>That will load up jQuery from Google.</p>
<p>Now you just need to include this in your site&#8217;s footer, before the closing <code>&lt;body&gt;</code>. (Why in the footer? Because including your JavaScript after all of your code is the efficient way to do it.)</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> thePage <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  thePage.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>thePage.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/jQuery/ig</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'&lt;a href=&quot;http://jquery.com&quot;&gt;jQuery&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>Since jQuery doesn&#8217;t have a core function for replacing text, we will use the JavaScript <code><a href="http://www.w3schools.com/jsref/jsref_replace.asp">replace()</a></code> function. The <code>i</code> after the slash makes the search and replace case-insensitive, and the <code>g</code> makes it global. </p>
<p>I have the script working on this page to replace every instance of the word jQuery with a link to the jQuery Web site.</p>
<p><script type="text/javascript">
(function($) {
  $(".posttop p").each(function() {
    $(this).html($(this).html().replace(/jQuery/ig, '<a href="http://jquery.com">jQuery</a>')); 
  });
})(jQuery)
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/tutorials/jquery-replace-word-with-link/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
