<?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>Fuel Your Coding &#187; Concepts &amp; Training</title>
	<atom:link href="http://fuelyourcoding.com/category/devtools/concepts/feed/" rel="self" type="application/rss+xml" />
	<link>http://fuelyourcoding.com</link>
	<description></description>
	<lastBuildDate>Mon, 09 Aug 2010 14:40:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Jquery, JQuery and Asking for help</title>
		<link>http://fuelyourcoding.com/jquery-jquery-and-asking-for-help/</link>
		<comments>http://fuelyourcoding.com/jquery-jquery-and-asking-for-help/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 09:00:15 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=1223</guid>
		<description><![CDATA[A few weeks ago, I tweeted:
General service announcement: it is written &#8220;jQuery&#8221; not &#8220;Jquery&#8221; or &#8220;JQuery&#8221;&#8230; even if it comes first in a sentence!!!! ∞
Then Saturday I put out a stronger tweet, and caught some stronger feedback for it:
Test: &#8220;If you want jQuery help, which misspelling will greatly hurt your chances: a) Jquery b) JQuery c) [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/jquery-jquery-and-asking-for-help/">Jquery, JQuery and Asking for help</a></p>
]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, I tweeted:</p>
<blockquote><p>General service announcement: it is written &#8220;jQuery&#8221; not &#8220;Jquery&#8221; or &#8220;JQuery&#8221;&#8230; even if it comes first in a sentence!!!! <a href="http://twitter.com/dougneiner/status/15858703370">∞</a></p></blockquote>
<p>Then Saturday I put out a stronger tweet, and caught some stronger feedback for it:</p>
<blockquote><p>Test: &#8220;If you want jQuery help, which misspelling will greatly hurt your chances: a) Jquery b) JQuery c) jquery d) All of the above. <a href="http://twitter.com/dougneiner/status/18214276476">∞</a></p></blockquote>
<p>At the end of the day, does it really matter how someone writes the name &#8220;jQuery&#8221;? Does it make them a better or worse programmer based on how they type it out?</p>
<p>Let me clarify that I have never failed to answer a question on Stack Overflow (Where I like to hang out and answer jQuery questions) because the asker typed jQuery with incorrect capitalization. <strong>I would never fail to respond to an email because the asker wrote it as Jquery or JQuery.</strong> I would hate to be that petty an individual, and I think that is the feeling some people were picking up from my tweets.</p>
<p>However, I can say I <em>notice</em> it and it <em>bothers me</em> when people seeking help don&#8217;t type out the library name correctly. It really is a small thing, and maybe it shouldn&#8217;t bother me, but it does. It got me thinking about things that might negatively affect a request for help, and I came up with a list of six suggestions. I hope these suggestions are helpful when you need to ask for help with open source software.</p>
<h2>Asking for Help</h2>
<p>If you need help with an open source project, you will often be dealing with people that 1) don&#8217;t have a lot of time and 2) must use the time they have wisely. With that in mind, here are few suggestions that might help you get answers easier:</p>
<ol>
<li>Take the time to <strong>make sure your question makes sense</strong>. Complete sentences, clear code examples, and links to a page demonstrating the problem all go a long way in ensuring a quality answer.</li>
<li><strong>Run spell-check</strong> before sending your question. There are at least two reasons there would be a lot of spelling errors in a question: 1) English is not the native tongue of the person requesting help 2) The person requesting help didn&#8217;t take the time ensure a quality question. Most applications have spell check. If they don&#8217;t, you can copy and paste your question to an application that does have spell check. Reason #1 is understandable and should be overlooked; reason #2 is what will stand out most to someone reading your question. It may affect that person&#8217;s decision to answer you.</li>
<li>Getting back to my original statement regarding Jquery, JQuery and jquery. Some libraries have really weird spelling or capitalizations, some are more straight forward. <strong>Write the library/plugin name correctly when asking for help with it!</strong> jQuery should be very easy, but so many people get it wrong. It is like the names iPad and iPhone: the first letter is lowercase! For another example, the popular blogging platform is WordPress, not Wordpress or Word Press.</li>
<li>At the very least, <strong>run a Google/Yahoo/Bing search (pick one) </strong>with some of the words from the question you plan on asking. I almost always take time to run a few searches to answer a question myself before asking on Stack Overflow or emailing someone for help. It is just common courtesy to spend some of <em>your</em> time before asking for the time of <em>someone else</em>.</li>
<li>If you find the answer yourself after asking for help, <strong>be sure to let the person know you no longer need their help</strong>. Sometimes emails will sit around until there is time to answer them while in the mean time you find the answer somewhere else. It might reduce your chance of getting future emails answered if the person who takes the time to answer your question finds out they wasted their time.</li>
<li><strong>Be respectful and kind.</strong> If an open source project is screwing up your project, you have a few choices 1) use a different project 2) pay for help 3) Ask kindly for help from the project. Notice I didn&#8217;t put &#8220;4) Demand help for free.&#8221; On a very positive note, I have to say every request I have gotten for help on the few small projects I maintain have been both respectful and kind. This is really important!</li>
</ol>
<h2>What It All Means</h2>
<p>The bottom line is this: <em>If it appears to someone reading your question that you have not put any time into either solving the problem yourself or writing a decent request for help, they will be less likely to put any time into answering it.</em></p>
<p>Remember, it isn&#8217;t always about just getting an answer. Sometimes its about getting the <em>right person</em> to answer your question. For instance, there are tons of programmers answering questions on Stack Overflow, but not all of them have equal qualifications and skill. Put in the effort up front when asking the question. It will be worth it when you get a solid answer!</p>
<p>Do you have any tips to add? If so, please let me know about them in the comments!</p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/jquery-jquery-and-asking-for-help/">Jquery, JQuery and Asking for help</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/jquery-jquery-and-asking-for-help/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>One Sure-Fire Way to Improve Your Coding</title>
		<link>http://fuelyourcoding.com/one-sure-fire-way-to-improve-your-coding/</link>
		<comments>http://fuelyourcoding.com/one-sure-fire-way-to-improve-your-coding/#comments</comments>
		<pubDate>Thu, 27 May 2010 13:25:35 +0000</pubDate>
		<dc:creator>Jerod Santo</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=1086</guid>
		<description><![CDATA[The most obvious way to improve your coding is to write more code. Everybody knows that. However, another activity which I guarantee will improve your coding is the complete opposite of writing. I will state this as plainly as I possibly can:
If you want to dramatically increase your programming skills you need to be reading [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/one-sure-fire-way-to-improve-your-coding/">One Sure-Fire Way to Improve Your Coding</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The most obvious way to improve your coding is to write more code. Everybody knows that. However, another activity which I guarantee will improve your coding is the complete opposite of writing. I will state this as plainly as I possibly can:</p>
<p><strong>If you want to dramatically increase your programming skills you need to be reading other people&#8217;s code.</strong></p>
<p>Maybe you believe that, maybe you don&#8217;t. You should. And if you&#8217;re willing to give it a shot, I believe you will be rewarded greatly for your time.</p>
<p>In this article I will help you choose what to read and give you practical advice on how to go about reading it. If you&#8217;re already a code reader you may find a few ways to get more from your efforts. If you aren&#8217;t, you absolutely must read on.</p>
<h2>What to Read</h2>
<p>This is a big decision, and one that is difficult to advise on. I won&#8217;t simply point you toward code I think you should read, because it really comes down to what you&#8217;re in to. However, I will provide some guidelines which you can follow to help you choose what to read.</p>
<h3>&raquo; Read Code That You Rely On</h3>
<p>A great place to start is with any plugins or libraries that you are already using.</p>
<ul>
<li>A WordPress plugin that you really like</li>
<li>A Ruby gem that you&#8217;ve found useful</li>
<li>A jQuery plugin that you keep going back to</li>
</ul>
<p>These are all great candidates for learning. You are already familiar with their public APIs so the barrier to understanding their inner workings is lower. Also, as a user of the code you have an opportunity to add documentation, implement a new feature, or generally give back to the project in some way.</p>
<h3>&raquo; Read Code That Impresses You</h3>
<p>I remember the first time I saw <a href="http://280slides.com">280 Slides</a> and I thought to myself, &#8220;Now that is impressive.&#8221; I quickly learned that the code driving that site was the open-source <a href="http://cappuccino.org">Cappuccino</a> project. I tucked that knowledge into the far recesses of my brain and when I eventually came across <a href="http://almost.at">another impressive app</a> running on <a href="http://cappuccino.org">Cappuccino</a> I knew I had a project that I could learn a lot from. What have you been impressed by lately? Is it open-source? If so, it&#8217;s a great choice for reading since the code is likely to impress you as much as the resulting application.</p>
<h3>&raquo; Read Code Written By Somebody You Respect</h3>
<p>If you&#8217;ve been coding with open-source software for more than a little while, there are probably other programmers who have earned your respect. I can think of <a href="http://github.com/defunkt">a</a> <a href="http://github.com/defunkt">few</a> <a href="http://github.com/jashkenas">developers</a> off the top of my head whose code is downright enviable.</p>
<p style="text-align: center;"><img src="http://fuelyourcoding.com/files/follow-coders.png" alt="follow-coders" title="follow-coders" width="438" height="88" class="aligncenter size-full wp-image-1097" /></p>
<p>If you don&#8217;t have a respected developer in mind, it&#8217;s easy to find one. He or she has probably authored some code in one of the previous two sections (code you rely upon, or that impresses you).</p>
<h3>&raquo; Read Code That You Can Actually Grok</h3>
<p>If you&#8217;re the adventurous type you may be considering diving into a large project like <a href="http://rubyonrails.org">Ruby on Rails</a>, <a href="http://drupal.org/">Drupal</a>, or <a href="http://jquery.com/">jQuery</a>. I suggest avoiding projects like these for now unless you are an experienced code reader.</p>
<p>Large projects have a lot more moving pieces, and you may end up struggling too much with the concepts to learn anything of immediate value. Confusion leads to discouragement, and larger projects more likely to confuse and discourage you in your reading. The advantage of picking a small project to read is that you can hold the entire program logic in your head at once. This leaves you with just the details to discover and learn from.</p>
<h2>How to Read</h2>
<p>Now that you&#8217;ve chosen some code to read, what is the best way to go about reading it? I&#8217;ve read a lot of code in my days, and I can suggest a few ways to maximize your ROI.</p>
<h3>&raquo; See the Big Picture</h3>
<p>I&#8217;m going to assume that you at least know at a macro level what the code you&#8217;re reading accomplishes. If not, I suggest reading the project&#8217;s website, tutorials, documentation, and anything else you can get your hands on except the code.</p>
<p>Okay, with that cleared I suggest your first step is to wrap your head around the project&#8217;s structure. This is a variable amount of work depending on the size of the codebase you&#8217;ve chosen, but anything larger than one file will require a little bit of time.</p>
<p>First, note the file structure. This step is aided by an editor that has a folder hierarchy view like <a href="http://macromates.com">TextMate</a>. For example, here is a nice overview of the <a href="http://github.com/jnunemaker/twitter">Twitter</a> Ruby gem:</p>
<p style="text-align: center;"><img src="http://fuelyourcoding.com/files/twitter-folder-structure.png" alt="twitter-folder-structure" title="twitter-folder-structure" width="230" height="510" class="aligncenter size-full wp-image-1090" /></p>
<p>The goal with this step is to just get familiar with the source. Find out which files include/require/load other files, where the bulk of the code is, the namespaces used if any, and things of this nature. Once you&#8217;ve got the big picture you&#8217;ll be ready to dig into the details.</p>
<h3>&raquo; Document Your Findings</h3>
<p>Reading code should not be a passive activity. I encourage you to add comments as you go, documenting your assumptions and your conclusions as you begin to understand the program flow. When you first get started your comments will probably look something like:</p>
<pre class="brush: ruby;">
# I think this function is called after 'initialize'
</pre>
<pre class="brush: ruby;">
# What does this equation even do?
</pre>
<pre class="brush: ruby;">
# Pretty sure this variable loses scope after line 17
</pre>
<p>As your understanding progresses you can remove the little breadcrumb comments you left yourself and perhaps write more meaningful and authoritative comments that could possibly be committed back to the project.</p>
<h3>&raquo; Use the Tests, Luke</h3>
<p>Hopefully the project you&#8217;ve chosen has a test suite. If not, you can skip this section altogether (or find one that does).</p>
<p>Tests are a great place to start whenever you read somebody else&#8217;s code because they document what the code is supposed to accomplish. Some tests are more informative than others, but no matter how well written, you&#8217;ll often find the programmer&#8217;s intent in the tests much more easily than you&#8217;ll find it in the implementation. While you&#8217;re reading, try to get the test suite to run successfully. This will make sure your development environment is configured properly and will make you more confident when making changes.</p>
<h3>&raquo; Execute, Change Stuff, Execute</h3>
<p>Who said reading code had to be hands off? You&#8217;ll really start to understand things once you&#8217;ve broken everything and put it back together again. Remember those tests you got passing? Make them fail, add some more, or try changing the implementation without breaking them. Try adding a small feature that you think is cool, or setup project-wide logging so you can print output at various stages of the code. Is this still reading? Absolutely, but at this point its more of a choose your own adventure than a mystery novel. And that&#8217;s a good thing!</p>
<h3>&raquo; Rinse and Repeat</h3>
<p>Once you finish reading one codebase, pick another one and start the process over again. The more code you read, the better you get at reading it and the more you get out of it in less time. I think you&#8217;ll find that the ROI increases quite quickly and that it&#8217;s actually a very enjoyable way to learn.</p>
<h2>Where To Start</h2>
<p>The single most influential factor in my code reading is <a href="http://github.com">GitHub</a>. The site makes it so easy to find new projects and great coders that you&#8217;re doing yourself a disservice if you&#8217;re not leveraging it. I suggest starting on <a href="http://github.com">GitHub</a> and reading code right on the site until you find a project you know you can learn from. Then <tt>git clone</tt> that baby and get to reading!</p>
<p><strong>How about you? Do you read code as a learning tool? Which projects would you recommend to others? Read any good code lately?</strong></p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/one-sure-fire-way-to-improve-your-coding/">One Sure-Fire Way to Improve Your Coding</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/one-sure-fire-way-to-improve-your-coding/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>Create a simple &#8220;shop&#8221; page in Textpattern</title>
		<link>http://fuelyourcoding.com/create-a-simple-shop-page-in-textpattern/</link>
		<comments>http://fuelyourcoding.com/create-a-simple-shop-page-in-textpattern/#comments</comments>
		<pubDate>Thu, 20 May 2010 12:32:19 +0000</pubDate>
		<dc:creator>Marie Poulin</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Textpattern]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=881</guid>
		<description><![CDATA[This tutorial assumes that you have a fairly strong understanding of  HTML and CSS, as well as a basic understanding of Textpattern and its  tags. (I won&#8217;t be going into detail about the css) We will be building a very simple &#8220;shop&#8221; type page in Textpattern.  There are plugins which allow Textpattern [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/create-a-simple-shop-page-in-textpattern/">Create a simple &#8220;shop&#8221; page in Textpattern</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This tutorial assumes that you have a fairly strong understanding of  HTML and CSS, as well as a basic understanding of Textpattern and its  tags. (I won&#8217;t be going into detail about the css) We will be building a very simple &#8220;shop&#8221; type page in Textpattern.  There are plugins which allow Textpattern to integrate paypal support,  but this is a fairly simple alternative. This allows you to feature  products which you may sell through paypal, e-junkie, Amazon (or  whatever else you may be using) The structure of this page is built with  the client in mind &#8211; they don&#8217;t need to format the page with any html  or div&#8217;s in order to get the products laid out nicely.</p>
<p>Two example links of this simple functionality in action are:</p>
<p>1. <a href="http://www.meghantelpner.com/shop/?c=books" target="_blank">http://www.meghantelpner.com/shop/?c=books</a></p>
<p>2. <a href="http://www.elmwoodspa.com/shop/">http://www.elmwoodspa.com/shop/</a></p>
<p>In the first example, you can click on one of Meghan&#8217;s books to see more information before deciding to purchase. If you click on &#8220;buy now&#8221;, you will be taken to her e-junkie store. Additionally, if you click on a specific book to see more information, you get a small navigation block at the top of the article that allows you to quickly browse the next and previous products. You may notice that if you click on one of the other submenus within her store, such as the Books/DVDs/Audio, that you will be taken directly to the Amazon affiliate link for that product. The client has the capacity to choose whether or not to link the product to an external link (Amazon, e-junkie, paypal) or whether or not to link to the full product page itself first, with a &#8220;buy now&#8221; button.</p>
<p>In the second example, you can click to see details/shop online which takes you immediately to Elmwood Spa&#8217;s online store.</p>
<p>I will be using the first example as a basis for the tutorial.</p>
<p>Plugins used: <a href="http://textpattern.org/plugins/470/cbs_category_list">cbs_category_list</a>, <a href="http://textpattern.org/plugins/186/zem_nth">zem_nth</a> (both optional) and <a href="http://utterplush.com/txp-plugins/upm-image">upm_image</a></p>
<p>First you&#8217;ll want to set up some custom fields, depending on how you want your shop to function. For Meghan&#8217;s shop, there are instances where she links to external products via a buy now button. Other times, she&#8217;ll want to link to an external site without the buy now button. So I have created 2 custom fields, &#8220;link to this site&#8221; and &#8220;buynow.&#8221; If you link exclusively to Paypal links, you could name it paypal, or whatever is easy for you to remember. (As long as you adjust it accordingly in the article forms)</p>
<p><img class="alignnone size-full wp-image-883" title="customfields" src="http://fuelyourcoding.com/files/customfields.jpg" alt="customfields" width="547" height="99" /></p>
<p>Now let&#8217;s take a look at one of the product pages inside textpattern:</p>
<p><img class="alignnone size-full wp-image-884" title="shop1" src="http://fuelyourcoding.com/files/shop1.jpg" alt="shop1" width="606" height="411" /></p>
<p>1. The title that will appear on the shop landing page</p>
<p>2. The description that will appear only one the item is clicked on</p>
<p>3. This is the link that the thumbnail and title will link to if you put a link (full url) here, otherwise:</p>
<p>4. A buy now button will appear and will link to the full url pasted here (if a link is not placed in either field, the title and thumbnail will merely link to the full article page automatically)</p>
<p>5. Place the image id number here that you want to associate with the article (the thumbnail version of this image will appear on the shop landing page, while the full image size will show on the individual article page.)</p>
<p>6. Choose the appropriate section for your article, in this instance, &#8220;shop.&#8221;</p>
<p>7. Select the appropriate categoryfor the article (if applicable. You may not have a need for categories)</p>
<p>8. IF USING THE BUY NOW FIELD you must use the override form named shop_listing2 (I&#8217;ll explain below)</p>
<p>SAVE your article!</p>
<div id="attachment_886" class="wp-caption alignnone" style="width: 616px"><img class="size-full wp-image-886" title="shop2" src="http://fuelyourcoding.com/files/shop2.jpg" alt="shop subnav" width="606" height="365" /><p class="wp-caption-text">shop subnav</p></div>
<p>In the actual page template for the shop, the code that calls the shop submenu (books and guides, etc) looks like this:</p>
<pre class="brush: xml;">&lt;txp:cbs_category_list parent=&quot;shop&quot; wraptag=&quot;ul&quot; break=&quot;li&quot; class=&quot;subnav&quot; section=&quot;shop&quot; showcount=&quot;false&quot; class=&quot;subnav&quot; activeclass=&quot;active&quot;/&gt;</pre>
<p>Using the plugin cbs_category_list, this pulls a list of all of the categories with a parent category of &#8220;shop&#8221;, wraps each category in a list tag, wraps the whole thing in an unordered list with a class of subnav, and assigns a class of active on list items when they are active. Handy dandy! You don&#8217;t necessarily need to use this plugin if your shop does not need this type of subnav.</p>
<p>Ok, so how do we pull all of our shop items into the page? The article tag in our shop page template looks like this:</p>
<div>
<pre class="brush: xml;">&lt;txp:article listform=&quot;shop_listing&quot; form=&quot;shop&quot; limit=&quot;99&quot; sort=&quot;posted asc&quot;/&gt;</pre>
</div>
<p>So this tag basically says: on the landing page (or listform version of the page), display the articles using the form of &#8220;shop_listing&#8221;. If you&#8217;re looking at an individual article page, (i.e. an individual product page) display the article using the form &#8220;shop&#8221;. Limit the amount of articles shown to 99, and sort them by date of Posted Ascending.</p>
<p>The &#8220;shop_listing&#8221; form looks like this:</p>
<div>
<pre class="brush: xml;">&lt;div class=&quot;shop-item&quot;&gt;  &lt;a href=&quot;&lt;txp:permlink  /&gt;&quot;&gt;&lt;txp:upm_article_image type=&quot;thumbnail&quot;  class=&quot;shopimg&quot;/&gt;&lt;/a&gt;  &lt;h3&gt;&lt;txp:permlink&gt;&lt;txp:title  /&gt;&lt;/txp:permlink&gt;&lt;/h3&gt;  &lt;span&gt;&lt;a href=&quot;&lt;txp:custom_field  name=&quot;buynow&quot; /&gt;&quot;&gt;BUY NOW&lt;/a&gt;&lt;/span&gt;  &lt;/div&gt;</pre>
</div>
<p>Translation: the thumbnail version of the article&#8217;s image is being pulled from the &#8220;Article image&#8221; field in the article, and assigned the class of &#8220;shopimg&#8221; for styling purposes. Both the title and thumbnail are linked to the permanent link to the article (which will show the body/description of the product. The Buy Now button links to whatever gets put into the custom field named &#8220;buynow.&#8221; The shop-item css looks something like: .shop-item {float:left; margin:20px 25px 10px 0; width:175px; }</p>
<p><em>Alternately, if you want to get really nerdy, you could use the plugin <a href="http://textpattern.org/plugins/186/zem_nth">zem_nth</a> to tell every third (or whatever number) post to display with different class. I use it to apply &#8220;shop-item-last&#8221; (<span style="font-style: normal;"><em>which has a margin-right of zero) <span style="font-style: normal;"><em>to every third item , so the last item in every row doesn&#8217;t have any extra margin space on the right. You can choose to do your layouts with or without zem_nth. This is what my shop_listing article form really looks like:</em></span></em></span></em></p>
<pre class="brush: xml;">&lt;txp:zem_nth step=&quot;1&quot; of=&quot;3&quot;&gt;&lt;div class=&quot;shop-item&quot;&gt;&lt;/txp:zem_nth&gt;&lt;txp:zem_nth step=&quot;2&quot; of=&quot;3&quot; &gt;&lt;div class=&quot;shop-item&quot;&gt;&lt;/txp:zem_nth&gt;&lt;txp:zem_nth step=&quot;3&quot; of=&quot;3&quot; &gt;&lt;div class=&quot;shop-item-last&quot;&gt;&lt;/txp:zem_nth&gt;&lt;a href=&quot;&lt;txp:permlink /&gt;&quot;&gt;&lt;txp:upm_article_image type=&quot;thumbnail&quot; class=&quot;shopimg&quot;/&gt;&lt;/a&gt;&lt;h3&gt;&lt;txp:permlink&gt;&lt;txp:title /&gt;&lt;/txp:permlink&gt;&lt;/h3&gt;&lt;span class=&quot;register&quot;&gt;&lt;a href=&quot;&lt;txp:custom_field name=&quot;buynow&quot; /&gt;&quot;&gt;BUY NOW&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;txp:zem_nth step=&quot;3&quot; of=&quot;3&quot; &gt;&lt;hr class=&quot;space&quot; /&gt;&lt;/txp:zem_nth&gt;</pre>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2145px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;txp:zem_nth step=&#8221;1&#8243; of=&#8221;3&#8243;&gt;&lt;div&gt;&lt;/txp:zem_nth&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2145px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;txp:zem_nth step=&#8221;2&#8243; of=&#8221;3&#8243; &gt;&lt;div&gt;&lt;/txp:zem_nth&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2145px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;txp:zem_nth step=&#8221;3&#8243; of=&#8221;3&#8243; &gt;&lt;div&gt;&lt;/txp:zem_nth&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2145px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;a href=&#8221;&lt;txp:permlink /&gt;&#8221;&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2145px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;txp:upm_article_image type=&#8221;thumbnail&#8221;/&gt;&lt;/a&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2145px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;h3&gt;&lt;txp:permlink&gt;&lt;txp:title /&gt;&lt;/txp:permlink&gt;&lt;/h3&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2145px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;span&gt;&lt;a href=&#8221;&lt;txp:custom_field name=&#8221;buynow&#8221; /&gt;&#8221;&gt;BUY NOW&lt;/a&gt;&lt;/span&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2145px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;/div&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2145px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;txp:zem_nth step=&#8221;3&#8243; of=&#8221;3&#8243; &gt;&lt;hr /&gt;&lt;/txp:zem_nth&gt;</div>
<p>The &#8220;shop_listing2&#8243; form (for products without a buy now button, linking externally) looks like this:</p>
<div>
<pre class="brush: xml;">&lt;div class=&quot;shop-item&quot;&gt;
 &lt;a href=&quot;&lt;txp:custom_field name=&quot;link to this site&quot; /&gt;&quot;  rel=&quot;external&quot;&gt;&lt;txp:upm_article_image type=&quot;thumbnail&quot;  class=&quot;shopimg&quot;/&gt;&lt;/a&gt;
 &lt;h3&gt;&lt;a href=&quot;&lt;txp:custom_field name=&quot;link to this site&quot;  /&gt;&quot;&gt;&lt;txp:title /&gt;&lt;/a&gt;&lt;/h3&gt;
 &lt;/div&gt;</pre>
</div>
<p>This tells the title and thumbnail on the listing page to link directly (in a new window/tab) to the link that is found in the &#8220;link to this site&#8221; field shown in the image above, #3. You could also include the &lt;txp:excerpt /&gt; tag if you wanted to include an excerpt. If you want the article to appear this way (without the buy now button), you need to ensure that you are using the override_form in the article named &#8220;shop_listing2&#8243;.</p>
<p>Now that we have set up what the listing page looks like for product pages, let&#8217;s look at how the individual product pages look. If you will recall the article form we used:</p>
<div>
<pre class="brush: xml;">&lt;txp:article listform=&quot;shop_listing&quot; form=&quot;shop&quot; limit=&quot;99&quot;  sort=&quot;posted asc&quot;/&gt;</pre>
</div>
<p>We need to create a form called &#8220;shop&#8221; that will determine how the individual pages look once you click on the thumbnail/title.</p>
<p>The &#8220;shop&#8221; article form looks like this:</p>
<div>
<pre class="brush: xml;">&lt;p&gt;&lt;a href=&quot;/shop&quot;&gt;Back to Shop&lt;/a&gt; |  &lt;txp:link_to_prev&gt;Previous Product&lt;/txp:link_to_prev&gt; |  &lt;txp:link_to_next&gt;Next Product&lt;/txp:link_to_next&gt;&lt;/p&gt;
 &lt;div class=&quot;right&quot;&gt;&lt;txp:upm_article_image/&gt;&lt;br /&gt;&lt;span  class=&quot;register&quot; &gt;&lt;a href='&lt;txp:custom_field  name=&quot;buynow&quot;/&gt;' &gt;BUY NOW&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;txp:body /&gt;</pre>
</div>
<p>Translation: The tags inside the paragraphs set up a small subnav which allows the user to click through to the next/previous products. Then it puts the full version of the article image in a div labelled &#8220;right&#8221; (which I float right in my css), below that place a Buy Now button which links to the url provided in the &#8220;buynow&#8221; custom field. Then display the body of the article. You could of course format the tags however you want. (image on top with text below, etc). Individual product page pictured below:</p>
<div id="attachment_888" class="wp-caption alignnone" style="width: 616px"><img class="size-full wp-image-888" title="individualpage" src="http://fuelyourcoding.com/files/individualpage.jpg" alt="individual product page" width="606" height="525" /><p class="wp-caption-text">individual product page</p></div>
<p>Using custom fields is a great way to allow the client (who doesn&#8217;t know how to code) to be able to add new items to the shop easily without having to see any textpattern or html tags, and avoid them forgetting to close link tags and add things like rel=&#8221;external&#8221;. Yay!</p>
<p>This tutorial assumes that you have textpattern installed and ready to go, and have a good grasp of the tags.</p>
<p>( Download the latest version of Textpattern here: http://textpattern.com/download )</p>
<p>Did I miss anything? If you need any more clarity or have any questions, please feel free to put them in the comments, and I will do my best to help.</p>
<p>Happy Coding!</p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/create-a-simple-shop-page-in-textpattern/">Create a simple &#8220;shop&#8221; page in Textpattern</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/create-a-simple-shop-page-in-textpattern/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Debugging with WordPress</title>
		<link>http://fuelyourcoding.com/simple-debugging-with-wordpress/</link>
		<comments>http://fuelyourcoding.com/simple-debugging-with-wordpress/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 19:13:36 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[wp_debug]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=826</guid>
		<description><![CDATA[For simple WordPress theme development, what is the first thing most PHP developers do to troubleshoot problems?

print_r( $post );
die();

One the statements are in place, the programmer refreshes the page and looks at the source to view a nicely indented array or object. Next they comment out the print_r and die statements, change some lines, and [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/simple-debugging-with-wordpress/">Simple Debugging with WordPress</a></p>
]]></description>
			<content:encoded><![CDATA[<p>For simple WordPress theme development, what is the first thing most PHP developers do to troubleshoot problems?</p>
<pre class="brush: php;">
print_r( $post );
die();
</pre>
<p>One the statements are in place, the programmer refreshes the page and looks at the source to view a nicely indented array or object. Next they comment out the <tt>print_r</tt> and <tt>die</tt> statements, change some lines, and try the code again. If it fails, they are back to square one and in go the <tt>print_r</tt>,<tt>echo</tt> and <tt>die</tt> statements so the brutal cycle can begin again.</p>
<p>We know these methods <em>partially</em> work (who hasn&#8217;t done the above during a PHP project!), but we also know they are less than optimal. Is there a better way?</p>
<h2>WordPress Debug Mode</h2>
<p>WordPress offers quite a few ways to enable and customize a debug mode while developing. To enable debug mode, you want to define <tt>WP_DEBUG</tt> as <tt>true</tt> in your wp-config.php. Here is the complete code block I suggest you use. We will look at the individual parts shortly. Place this in your <tt>wp-config.php</tt> file after the lines that define the database variables. Be sure to change <tt>development_user</tt> to be your development database user name:</p>
<pre class="brush: php;">
@ini_set('display_errors',0);
if( 'development_user' === DB_USER ){
  define('WP_DEBUG',         true);  // Turn debugging ON
  define('WP_DEBUG_DISPLAY', false); // Turn forced display OFF
  define('WP_DEBUG_LOG',     true);  // Turn logging to wp-content/debug.log ON
}
</pre>
<h3>display_errors</h3>
<p>The first line in our code block turns off the display of errors, regardless of php.ini or .htaccess settings to the contrary. This is important because though WordPress can force the display of errors to be on, it won&#8217;t force them to be off if <tt>display_errors</tt> is already turned on.</p>
<h3>Testing for local vs. production</h3>
<p>There are probably fifty ways of doing this part, so use a method that works for you. In my environments, my local development database rarely if <em>ever</em> has the same user name as the production database. Simply checking what I expect the local user name to be against what is defined in <tt>DB_USER</tt> is a simple way of knowing if the files are on the development or production servers.</p>
<h3>WP_DEBUG</h3>
<p>This is the most important constant as it determines if WordPress will use any of the other debugging constants. Thankfully it is quite simple. If set to <tt>true</tt>, debug mode is turned on. If <tt>undefined</tt> or set to <tt>false</tt>, debug mode is kept off.</p>
<h3>WP_DEBUG_DISPLAY</h3>
<p>This constant confused me at first, but it is actually quite simple. If set to <tt>true</tt>, it will override the current <tt>display_errors</tt> configuration setting and turn it on. However, if set to <tt>false</tt> it <strong>will not turn off <tt>display_errors</tt>.</strong> This setting is simply an override. This is the reason we turn <tt>display_errors</tt> off before setting any of these constants.</p>
<p>Set this constant to <tt>true</tt> if you want to see errors displayed in your browser when they occur. Keep in mind this will sometimes complicate errors because once at least one error has been written to the page, all redirect requests will fail. This is because the header information can no longer be modified once content is sent, and a displayed error counts as content.</p>
<h3>WP_DEBUG_LOG</h3>
<p>This constant is the whole reason I found the WordPress debug methods so helpful. Set this constant to <tt>true</tt> and WordPress will set up PHP to write to an error log in <tt>wp-content/debug.log</tt>. Sadly you can&#8217;t specify a different file location that is not in the content folder, but at least you know where it is!</p>
<p><em>Note: because this is written to a public directly, be extremely careful not to upload the log by mistake. Additionally, if you run WP_DEBUG on a production server, do so only for immediate troubleshooting then turn it off and remove <tt>wp-content/debug.log</tt>.</em></p>
<h2>Leveraging WP_DEBUG</h2>
<p>In addition to PHP errors being sent to <tt>debug.log</tt> we can also send our own output using the <tt>error_log</tt> PHP function. The only problem with this, is even in production mode your errors will still most likely be written to a PHP log; it just won&#8217;t be <tt>debug.log</tt>. Because of this, its a good idea to provide a wrapper function to handle the logging for your theme or plugin.</p>
<p>Place the following code in your <tt>functions.php</tt> in your theme, or in the plugin file for your WordPress plugin:</p>
<pre class="brush: php;">
if(!function_exists('_log')){
  function _log( $message ) {
    if( WP_DEBUG === true ){
      if( is_array( $message ) || is_object( $message ) ){
        error_log( print_r( $message, true ) );
      } else {
        error_log( $message );
      }
    }
  }
}
</pre>
<p>Feel free to expand on this function if it doesn&#8217;t exactly meet your needs, but the concept is simple: Centralize all your log calls to use your custom function. Then, in that <tt>_log</tt> function, only output the message if <tt>WP_DEBUG</tt> is set to <tt>true</tt>. There is no reason to test if <tt>WP_DEBUG</tt> has been defined because as soon as <tt>wp-settings.php</tt> is processed, <tt>WP_DEBUG</tt> <em>will be</em> defined, even if it wasn&#8217;t already defined in <tt>wp-config.php</tt>.</p>
<p>This particular <tt>_log</tt> snippet will call a <tt>print_r</tt> on arrays and objects passed to the function for simple debugging.</p>
<h2>Trying it Out</h2>
<p>If you have followed these steps, you can run a quick test by adding these lines into your <tt>header.php</tt> file in your theme folder:</p>
<pre class="brush: php;">
_log('Testing the error message logging');
_log(array('it' =&gt; 'works'));
</pre>
<p>After refreshing your page once, you should see a newly created <tt>debug.php</tt> file with a few lines of output. Use any log viewing utility that supports tailing the file for maximum productivity. On Mac, Unix and Linux systems, you can use this command from the main directory of your site:</p>
<pre class="brush: plain;">
tail -f wp-content/debug.log
</pre>
<h2>More Solutions</h2>
<p>If you are looking for a more interactive console for debugging, be sure to look at our review on the <a href="http://fuelyourcoding.com/plugin-review-wordpress-console/">WordPress Console</a>.</p>
<p><strong>What about you?</strong> If you didn&#8217;t already know about this built in WordPress feature, what methods did you come up with to make debugging WordPress easier? Please leave us your tips in the comments below!</p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/simple-debugging-with-wordpress/">Simple Debugging with WordPress</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/simple-debugging-with-wordpress/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Unconventional: CSS3 Link Checking</title>
		<link>http://fuelyourcoding.com/unconventional-css3-link-checking/</link>
		<comments>http://fuelyourcoding.com/unconventional-css3-link-checking/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 19:50:24 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=767</guid>
		<description><![CDATA[One of our regular writers Wess Cope lives by the principle that you should seek to push technology past its intended uses and beyond even its own limitations. From time to time we will be featuring unconventional uses of technology. Today, we look at unconventional CSS3:
The Problem
As a developer, you are rapidly building your newest [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/unconventional-css3-link-checking/">Unconventional: CSS3 Link Checking</a></p>
]]></description>
			<content:encoded><![CDATA[<p>One of our regular writers <a href="/about">Wess Cope</a> lives by the principle that you should seek to push technology past its intended uses and beyond even its own limitations. From time to time we will be featuring unconventional uses of technology. Today, we look at unconventional CSS3:</p>
<h2>The Problem</h2>
<p>As a developer, you are rapidly building your newest web creation. You start with the HTML, knowing full well you don&#8217;t have the hyperlinks you will need to complete the design. Nonetheless you put in:</p>
<pre class="brush: xml;">
&lt;ul id=&quot;nav&quot;&gt;
   &lt;li&gt;&lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href=&quot;&quot;&gt;About&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href=&quot;&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
   ...
&lt;/ul&gt;
</pre>
<p>What seems like a long time later, you get to the point where you finish up your site for demoing or production. How do you quickly find all those empty links? Well, you could use a link checker&#8230; or, just use CSS3!</p>
<h2>CSS3 Solution</h2>
<p>Just paste this line to the end of your last included CSS file for a quick visual display:</p>
<pre class="brush: css;">
/* Find all links where an href is not provided */
html body a:not([href]), html body a[href='']  { background: red !important;}
</pre>
<p>Then open your site in modern browser that supports CSS3, and any empty link now has a background of red. Edit your HTML, and check the page again. When all the links are fixed, none will have a red background!</p>
<p>You can see for yourself by checking a quick demo:<br />
<a target="_blank" href="http://fuelbrand.s3.amazonaws.com/coding/unconventional-css3/styles-off.html">Standard Page</a> | <a target="_blank"  href="http://fuelbrand.s3.amazonaws.com/coding/unconventional-css3/styles-on.html">Page With CSS3 Link Checking</a></p>
<h2>Bonus: Testing Progressive Enhancement</h2>
<p>For mission critical functionality it is generally good practice to have a fallback for non JavaScript users. To test if your page has any JavaScript only code, add this rule to your CSS file after the rule we just added:</p>
<pre class="brush: css;">
/* Find all links where the href = # */
html body a[href='#'] { background: yellow !important;}
</pre>
<p>Next, disable JavaScript in your browser (In Firefox and Safari it is an option in your preferences.).</p>
<p>Now, any of those links you cleverly enhanced with JavaScript, but forgot to add a valid fallback URL, will show up with a yellow background. If an item truly has application <em>only</em> when JavaScript is enable, you should consider adding it dynamically with JavaScript.</p>
<h2>Variations</h2>
<p>As a leftover vestige from IE6 days, many developers use <tt>href='#'</tt> so signify an empty url (So the <tt>:hover</tt> pseudo selector will still work). If this is your case, you have two options: 1) Change your style going forward and use <tt>href=''</tt> to signify an empty URL and <tt>href='#'</tt> for JavaScript enhanced links. or 2) Use only the second CSS3 rule and change the color to Red.</p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/unconventional-css3-link-checking/">Unconventional: CSS3 Link Checking</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/unconventional-css3-link-checking/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>JavaScript Can Learn: Now Teach It Tricks!</title>
		<link>http://fuelyourcoding.com/javascript-can-learn-now-teach-it-tricks/</link>
		<comments>http://fuelyourcoding.com/javascript-can-learn-now-teach-it-tricks/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 07:00:34 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[extending]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=672</guid>
		<description><![CDATA[When you do a lot of development with backend technologies, it can be frustrating to then move to the front end and feel like you are using a completely different syntax. One thing I really miss is the helper methods, especially when using Ruby on Rails on the server. Little helpers like titleize() or downcase() [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/javascript-can-learn-now-teach-it-tricks/">JavaScript Can Learn: Now Teach It Tricks!</a></p>
]]></description>
			<content:encoded><![CDATA[<p>When you do a lot of development with backend technologies, it can be frustrating to then move to the front end and feel like you are using a completely different syntax. One thing I really miss is the helper methods, especially when using Ruby on Rails on the server. Little helpers like <tt>titleize()</tt> or <tt>downcase()</tt> get replaced in javascript by a custom function and <tt>toLowerCase()</tt> respectively. You don&#8217;t have to feel lost anymore! There is a way you can extend the native objects found in JavaScript to make your environment feel a little more like &#8220;home.&#8221;</p>
<p>This is accomplished by using the prototype object. Each native object in JavaScript includes a prototype object. Don&#8217;t get this confused with the PrototypeJS framework&#8230; the prototype object is a way to extend <em>all</em> objects that have inherited from the base object you extended. You can easily extend the prototype object by adding functions to it like this:</p>
<pre class="brush: jscript;">
Object.prototype.functionName = function(){

}
</pre>
<p>You can then call them directly:</p>
<pre class="brush: jscript;">
var obj = new Object();
obj.functionName();
</pre>
<p>There are a number of advanced uses of the prototype object, but this is the important thing to remember: any function added to the prototype of an object is available on any object that inherits from it. So if you extend the prototype on the Number object, all numbers will have access to the new function; if you extend the Array object, all arrays can access your custom function. You only use the <tt>prototype.functionName</tt> syntax when declaring the new function, not when calling it.</p>
<p>Enough theory, lets see some (somewhat) practical uses:</p>
<p>Do you find yourself capitalizing a lot of words in a particular JavaScript app? Just add a <tt>capitalize</tt> method to the String object.</p>
<pre class="brush: jscript;">
String.prototype.capitalize = function(){
  if(this.length == 0) return this;
  return this[0].toUpperCase() + this.substr(1);
}
</pre>
<p>Now you can capitalize any string in your application by calling <tt>"lower".capitalize()</tt> and get <tt>"Lower"</tt> in return. Since it returns a string, you could chain it with any other function you can execute on a string.</p>
<p>Do you always find yourself forgetting you can call Number(&#8221;25&#8243;) to turn a string into a number? Just add a <tt>toNumber()</tt> function to the String prototype:</p>
<pre class="brush: jscript;">
String.prototype.toNumber = function(){
  return Number(this);
}

If you need to split large JSON arrays into groups of two or three each, you could extend the Array object like this:

[js]
Array.prototype.inGroupsOf = function(num){
	var ret = [],
		length = this.length,
		groups = Math.ceil(length / num);

	for(var i = 0; i &lt; groups; i++){
		var start = i * num,
			end   = start + num;

		ret.push(this.slice(start, end))
	}
	return ret;
}
</pre>
<p>Now calling <tt>inGroupsOf(3)</tt> on any Array would return that same array split into as many parts as needed to ensure no group has more than three items in it.</p>
<p>There are a number of objects you can extend, but the ones you will use the most are <tt>String</tt>, <tt>Array</tt>, <tt>Object</tt>, <tt>Number</tt>, <tt>Date</tt>. One trouble area you might face is calling methods on numbers. The following example will fail:</p>
<pre class="brush: jscript;">
Number.prototype.to_s = function(){
  return this + &quot;&quot;;
}

25.to_s();
</pre>
<p>The prototype function is correct, but the way we called it is wrong. There are two ways to call our custom functions on numbers:</p>
<pre class="brush: jscript;">
var n = 25;
n.to_s(); // Returns &quot;25&quot;

(25).to_s(); // Also returns &quot;25&quot;
</pre>
<h2>Think Start, Not End</h2>
<p>Its important when deciding what object to extend that you focus on what object type you are starting with, not so much which type you plan on ending with. For instance, if you wanted to extend an object to easily parse Twitter date strings you would not extend the <tt>Date</tt> object. You would extend the <tt>String</tt> object, and your function would return a <tt>Date</tt> object.</p>
<h2>Load Your Extensions First</h2>
<p>It is normally a good idea to load these extensions prior to any other library, including jQuery. Anytime you extend the prototype object, the new method is instantly available to all objects of the same type or any object that has inherited from that type. However, since you want to be sure your methods are always available, you guarantee their availability by loading them first.</p>
<h2>How to Group The Extensions</h2>
<p>Naming your files <tt>Prototype.Date.js</tt> and <tt>Prototype.Array.js</tt> is an easy way to keep all your extensions in one part of your JS folder, and easy to access during development. If you follow this method, you would simply put Date.prototype methods in the <tt>Prototype.Date.js</tt> file, etc. This starts to break down when you have parallel functions. You might have a <tt>toDateFromTwitter()</tt> method on the String object and a <tt>toTwitterFromDate()</tt> method on the Date object. Putting these in separate files might not make sense. At that point, you should put both these extensions in a file named TwitterHelpers.js or something similar. Obviously use what makes sense to you and works with your flow.</p>
<h2>Don&#8217;t Bloat</h2>
<p>Just because you write 500+ awesome Array extensions in the next 2 years, does not mean you need to include them on every project. Be sure to only use this technique when it makes sense for the project and when it helps clean up your code.</p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/javascript-can-learn-now-teach-it-tricks/">JavaScript Can Learn: Now Teach It Tricks!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/javascript-can-learn-now-teach-it-tricks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Roll Your Own PHP Framework: Part III</title>
		<link>http://fuelyourcoding.com/roll-your-own-php-framework-part-iii/</link>
		<comments>http://fuelyourcoding.com/roll-your-own-php-framework-part-iii/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 16:10:33 +0000</pubDate>
		<dc:creator>Wess Cope</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=652</guid>
		<description><![CDATA[In Part I and Part II we looked at how to set up our file structure, how to get URL routing working and how to set up templating for our little framework. In this final part to the series, we are going to briefly look at database access.
Mini-series Overview

Part 1: URL Routing and Directory Setup
Part [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/roll-your-own-php-framework-part-iii/">Roll Your Own PHP Framework: Part III</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://fuelyourcoding.com/php-frameworks-just-roll-your-own-part-1/">Part I</a> and <a href="http://fuelyourcoding.com/roll-your-own-php-framework-part-ii/">Part II</a> we looked at how to set up our file structure, how to get URL routing working and how to set up templating for our little framework. In this final part to the series, we are going to briefly look at database access.</p>
<p><strong>Mini-series Overview</strong></p>
<ul>
<li><a href="http://fuelyourcoding.com/php-frameworks-just-roll-your-own-part-1/">Part 1: URL Routing and Directory Setup</a></li>
<li><a href="http://fuelyourcoding.com/roll-your-own-php-framework-part-ii/">Part 2: Templating</a></li>
<li>Part 3: Database Interaction</li>
</ul>
<p>You can download all the files put together during this three part series here:</p>
<div class="post_buttons" style="margin-bottom: 20px"><a href="http://fuelyourcoding.com/files/peanut_framework.zip"><img class="size-full wp-image-24 alignnone" style="margin-left: 30px" src="http://fuelyourcoding.com/files/download-button.gif" alt="Download zipped archive" width="229" height="68" /></a></div>
<p>I&#8217;m not going into detail about how to create an ORM or ActiveRecord clone.  We are just going to write a simple helper class to setup our connection and query.  Also I&#8217;m going to assume you know how to create a database and table in the database.</p>
<p>I have created a database called &#8220;peanut&#8221; and created table:</p>
<pre class="brush: plain;">
users:
+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| id       | int(11)      | NO   | PRI | NULL    | auto_increment |
| username | varchar(255) | NO   |     | NULL    |                |
| password | varchar(255) | NO   |     | NULL    |                |
+----------+--------------+------+-----+---------+----------------+
</pre>
<p>In this example we are going to use Mysql and the php mysql_ methods.  So break open system/database.php and drop the following in:</p>
<pre class="brush: php;">
&lt;?php

// Here is where we are setting up a simple wrapper class around mysql
// functions just to make it a little more convenient.  Our models will
// simple extend our database class and simplify making queries just a bit.
class Database
{
	protected var $connection;
	// Every time you instantiate this class you are going to create
	// a new connection to the database.
	public function __construct()
	{
		// First we setup up a nice little connection to the database,
		// make sure you use your connection information.  If the
		// connection fails we just die with the error.
		$this-&gt;connection = mysql_pconnect(&quot;localhost&quot;, &quot;root&quot;, &quot;somepassword&quot;) or die(&quot;MySQL Error: &quot; . mysql_error());

		// And let's tell mysql which db we are going to use.
		mysql_select_db( &quot;peanut&quot;, $this-&gt;connection );
	}

	// This is just a helper function to help out against
	// possible sql injection attacks.
	public function escapeString($string)
	{
		// we call mysql's 'cleaning' function on strings
		// just to make sure we get a little safer item to query
		// with.
		return mysql_real_escape_string($string);
	}

	// Here we will query the database with the passed query string,
	// build up an array of objects and return them, simple enough.
	public function query($qry)
	{
		// Here we make our query and set the result to a $result variable
		$result = mysql_query($qry) or die(&quot;MySQL Error: &quot; . mysql_error());

		// Create a container array variable to hold all of our result objects.
		$resultObjects = array();

		// This might look weird, but all we are doing is saying,
		// While you are still getting results, please put the next
		// result into the next spot on my array.
		while($resultObjects[] = mysql_fetch_object($result));

		// Now we just return our array that has all our result objects in it
		return $resultObjects;
	}

	// Here we add a simplier method for handling INSERTs and UPDATEs since
	// they do not return a result set.
	public function execute($qry)
	{
		$exec = mysql_query($qry) or die(&quot;MySQL Error: &quot; . mysql_error());
		return $exec;
	}
}
?&gt;
</pre>
<p>So we have our database class in place and ready to use, now we just need to require it in the index.php like we did the others, so pop that bad boy open and after the template require, do one just like it but for the database.php</p>
<p>Now let&#8217;s crack open actions/helloworld/models.php and let&#8217;s write a simple addUser and getAllUsers method to it.  We are going to make our model a class as well so that it  can extend our Database class that we wrote.</p>
<p>Here are the guts:</p>
<pre class="brush: php;">
&lt;?php

// All of our database back-and-forth will be handled in our models file
// Don't be mistaken, this is no where close to an ORM (Object Relational Mapper)
// it's just simplified database access.

class myModel extends Database
{
	// When our model is instantiated we just need
	// to also instantiate our parent class (Database)
	// so it knows to make the connection to the database.
	public function __construct()
	{
		// We just call the __construct of Database class.
		parent::__construct();
	}

	// addUser will use the execute method of Database
	// since we are inserting a value and not expecting
	// anything in return.
	public function addUser($username, $password)
	{
		// Here we use that little cleaning method we
		// wrote to make our strings pretty and make sure
		// they will play nice with mysql
		$username = $this-&gt;escapeString($username);
		$password = $this-&gt;escapeString($password);

		// We execute our insert and if it worked $success
		// will be true else it will be false.
		$success = $this-&gt;execute(&quot;INSERT INTO users (username, password) VALUES ('{$username}','{$password}')&quot;);

		// We return $success to inform our page action that it has or hasn't worked.
		return $success;
	}

	// This method does just what you think it would.
	// We are going to use the query function because
	// we are expecting data back, then we are just
	// going to return the array of user objects.
	public function getAllUsers()
	{
		// Populate the $users variable with the results of our query
		$users = $this-&gt;query(&quot;SELECT * FROM users&quot;);

		// Now we return our results
		return $users;
	}
}
?&gt;
</pre>
<p>Now we need to change our actions/helloworld/actions.php mypage page action to:</p>
<pre class="brush: php;">
&lt;?php
// We need to include our models file so we can access the database
require(PEANUT_ROOT_DIR . 'actions/helloworld/models.php');

// We simply define the function (the second item in our request url)
// making sure it is the same name as the one in the url.

function mypage()
{
	// Let's do some database work!
	// Here we are going to instantiate our model
	$model = new myModel();

	// Now let's add a user
	// On a funny note, if you keep refreshing it will add this
	// user over and over in your users table so your getAllUsers call
	// will result in a list that grows by one each time.
	$model-&gt;addUser(&quot;wess&quot;, &quot;password&quot;);

	// Now let's fetch all of our users and put them in our users
	// variable.
	$users = $model-&gt;getAllUsers();

	// Let's create a new template object and pass it the path to our template
	$template = new Template(&quot;helloworld/templates/helloworld.php&quot;);

	// I bet you want to display a table in your template with all your newly
	// created users. So let's do it

	// That's write we use the same set command, and it will set our array of users
	// to our template variable $users, and since php is our template language
	// it's real easy to print them to the screen.
	$template-&gt;set('users', $users);

	// Set our page variable &quot;title&quot; with the value &quot;Hello World&quot;
	$template-&gt;set('title', 'Hello World');

	// Set our page variable &quot;message&quot; with our little message
	$template-&gt;set('message','This is my first message for my template');

	// Now we can call render and return it to dispatch to
	// display in our browser
	return $template-&gt;render();
}
?&gt;
</pre>
<p>So now you are handing all your users from your database to the template, so let&#8217;s display them. Change your <tt>actions/helloworld/templates/helloworld.php</tt> file to:</p>
<pre class="brush: xml;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;meta http-equiv=&quot;Content-type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
		&lt;title&gt;My PEANUT Page&lt;/title&gt;

	&lt;/head&gt;
	&lt;body&gt;
		&lt;h1&gt;&lt;?php echo $title ?&gt;&lt;/h1&gt;
		&lt;p&gt;&lt;?php echo $message ?&gt;&lt;/p&gt;

		&lt;h2&gt;Users:&lt;/h2&gt;
		&lt;table&gt;
			&lt;thead&gt;
				&lt;tr&gt;
					&lt;th&gt;ID&lt;/th&gt;
					&lt;th&gt;Username&lt;/th&gt;
					&lt;th&gt;Password&lt;/th&gt;
				&lt;/tr&gt;
			&lt;/thead&gt;
			&lt;tbody&gt;
				&lt;!--
					Here we are going to use native php foreach look
					to create each row of the table with our list of users.
					Notice how the foreach is done with a : and surrounding php tags.
				--&gt;
				&lt;?php foreach($users as $user): ?&gt;
					&lt;tr&gt;
						&lt;td&gt;&lt;?php echo $user-&gt;id ?&gt;&lt;/td&gt;
						&lt;td&gt;&lt;?php echo $user-&gt;username ?&gt;&lt;/td&gt;
						&lt;td&gt;&lt;?php echo $user-&gt;password ?&gt;&lt;/td&gt;
					&lt;/tr&gt;
				&lt;?php endforeach; ?&gt;
			&lt;/tbody&gt;
		&lt;/table&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Now if all went well, you should save all your files and open up: <a href="http://mywebapp.local/helloworld/mypage">http://mywebapp.local/helloworld/mypage</a> and see all the users that you added in a table.</p>
<p>So you have created a template class, url basic url routing, simplified database access, and a page action.  You have all the core basics of a PHP Framework at your hands now.  This is just for a starting point or foundation of understanding, please do not use this in a production environment.</p>
<p>I have really enjoyed writing this and I hope you learned something from my rambling!  The source code is available for download at the top of this article.</p>
<p>Take care,<br />
Wess &#8220;Wattz&#8221;</p>
<p><strong>Updated October 26, 2009: Thanks to Alex and Ian for spotting some errors in the code and supplying the fixes. The code examples have been updated to reflect the changes as has the ZIP file.</strong></p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/roll-your-own-php-framework-part-iii/">Roll Your Own PHP Framework: Part III</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/roll-your-own-php-framework-part-iii/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Easy to update thumbnail gallery using Textpattern and Galleriffic</title>
		<link>http://fuelyourcoding.com/easy-to-update-thumbnail-gallery-using-textpattern-and-galleriffic/</link>
		<comments>http://fuelyourcoding.com/easy-to-update-thumbnail-gallery-using-textpattern-and-galleriffic/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 16:22:10 +0000</pubDate>
		<dc:creator>Marie Poulin</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[portfolio]]></category>
		<category><![CDATA[Textpattern]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=631</guid>
		<description><![CDATA[This tutorial assumes that you have a fairly strong understanding of HTML and CSS. I have provided a basic style sheet with all necessary styles to achieve the look of gallery demo, but please feel free to edit the css. We will be building a very simple updateable thumbnail gallery using Textpattern and Galleriffic. There [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/easy-to-update-thumbnail-gallery-using-textpattern-and-galleriffic/">Easy to update thumbnail gallery using Textpattern and Galleriffic</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This tutorial assumes that you have a fairly strong understanding of HTML and CSS. I have provided a basic style sheet with all necessary styles to achieve the look of gallery demo, but please feel free to edit the css. We will be building a very simple updateable thumbnail gallery using <strong>Textpattern</strong> and <strong>Galleriffic</strong>. There are a few <a title="galleriffic txptips" href="http://txptips.com/galleriffic-image-gallery">tutorials</a> out there of a similar nature, but I have found this to be the simplest way to integrate Galleriffic with Textpattern.</p>
<div class="post_buttons"><a href="http://fuelyourcoding.com/files/tp_gallery.zip"><img class="size-full wp-image-24 alignnone" style="margin-left: 30px" src="http://fuelyourcoding.com/files/download-button.gif" alt="Download zipped archive" width="229" height="68" /></a></div>
<p>Below is a screen capture of the final gallery. To see the gallery in action, click <a title="Thumbnail Gallery" href="http://www.textpatternworkshops.com/gallery" target="_blank">here</a></p>
<p><img class="alignnone size-full wp-image-634" title="thumbnail gallery" src="http://fuelyourcoding.com/files/sample.jpg" alt="thumbnail gallery" width="606" height="350" /></p>
<p>This tutorial assumes that you have textpattern installed and ready to go.<br />
( Download the latest version of Textpattern here: <a title="textpattern download" href="http://textpattern.com/download" target="_blank">http://textpattern.com/download</a>)</p>
<h2>Galleriffic</h2>
<p>This gallery is based on Galleriffic, a jQuery plugin for rendering fast-performing photo galleries. This is adapted from <a title="galleriffic" href="http://www.twospy.com/galleriffic/" target="_blank">http://www.twospy.com/galleriffic/</a> to work with textpattern so you (and your clients!) can easily update the gallery. In a nutshell, the gallery works by associating image id #s with a specific article. The article form <strong>gallery</strong> and <strong>article_image_form</strong> work together to render the article in the form of all of the associated images (in their thumbnail format) to appear as an unordered list on the left, while the full version of the current image appears on the right. All that is necessary to add or change images, is to change the numbered list appearing in the advanced options on the left of the article containing the images. So easy once implemented, even a client that doesn&#8217;t speak nerd can add, subtract or change their own images.</p>
<h2>Upload the files</h2>
<p>Upload both of the galleriffic files included in the <strong>files</strong> folder of the download, by uploading them through the <strong>Content</strong> &gt; <strong>Files</strong> tab. I modified the jquery.galleriffic.js file so that the pagination does not appear above the thumbnails. Should you wish to further customize the gallery, I do suggest checking out the original <a title="galleriffic" href="http://www.twospy.com/galleriffic/" target="_blank">Galleriffic demo</a>.</p>
<h2>Install the relevant plugins</h2>
<p>Install the following plugins (these are included in the <strong>Plugins</strong> folder in the download):</p>
<ul>
<li> upm_image by Mary Fredbord – more powerful image display</li>
<li> ebl-image-edit by Eric Limegrover – introduces advanced image editing functionality</li>
</ul>
<p>(I have had technical issues with v.2 of this plugin, so I continue to use v1. Both are included in the plugin folder.)</p>
<p><strong>ebl-image-edit</strong> is great for sizing/creating thumbnails on the fly, without having Textpattern automatically centre the thumbnail. It is not essential to this tutorial, but it&#8217;s very very handy!</p>
<p><img class="alignnone size-full wp-image-635" title="thumbnailplugin" src="http://fuelyourcoding.com/files/thumbnailplugin.jpg" alt="thumbnailplugin" width="606" height="432" /></p>
<h2>Set up your forms</h2>
<p>You can find these forms in the <strong>forms</strong> folder in the download.</p>
<h3>gallery</h3>
<p>Create a new form called &#8220;gallery&#8221; and choose &#8220;article&#8221; for the type:</p>
<pre class="brush: xml;">

&lt;txp:upm_article_image form=&quot;article_image_form&quot; wraptag=&quot;ul&quot;
class=&quot;thumbs noscript&quot; /&gt;
</pre>
<h3>article_image_form</h3>
<p>Create a new form called &#8220;article_image_form&#8221; and choose &#8220;misc&#8221; for the type:</p>
<pre class="brush: xml;">

&lt;li&gt;&lt;a href=&quot;&lt;txp:upm_img_full_url /&gt;&quot; title=&quot;&lt;txp:upm_img_caption /&gt;&quot; class=&quot;thumb&quot;&gt;&lt;img src=&quot;&lt;txp:upm_img_thumb_url /&gt;&quot; alt=&quot;&lt;txp:upm_img_alt /&gt;&quot; /&gt;&lt;/a&gt;

&lt;div&gt;
&lt;div&gt;&lt;txp:upm_img_alt /&gt; &lt;/div&gt;
&lt;div&gt;&lt;txp:upm_img_caption /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
</pre>
<p>If you don&#8217;t want captions, delete the whole caption div.</p>
<p>Basically we have taken this code from galleriffic:</p>
<pre class="brush: xml;">

&lt;ul&gt; &lt;li&gt; &lt;a href=&quot;path/to/slide&quot; title=&quot;your image title&quot;&gt; &lt;img src=&quot;path/to/thumbnail&quot; alt=&quot;your image title again for graceful degradation&quot; /&gt; &lt;/a&gt; &lt;div&gt; (Any html can go here) &lt;/div&gt; &lt;/li&gt; ... (repeat for every image in the gallery) &lt;/ul&gt;
</pre>
<p>and modified it so the article forms generate this code from the image numbers that we will associate with the gallery article. We&#8217;re basically saying, &#8220;take the images associated with this article, put the thumbnail versions of those images on the left with these classes and this formatting, and put the full version of the selected image on the right.&#8221; Huh? Just follow along, I promise it will all make sense soon&#8230;</p>
<h2>Set up your page</h2>
<p>In the <strong>pages</strong> folder I have included a template for this gallery page (gallery.html). Create a new page template in textpattern: <strong>Presentation</strong> &gt; <strong>Pages</strong>. At the bottom, &#8220;copy page as&#8221;, name it <strong>gallery</strong>, and click &#8220;copy.&#8221; Make sure whatever section you are using for the gallery is in fact using the <strong>gallery</strong> page as its template. At the bottom of the page you will notice the galleriffic script. This is where you can make adjustments to sizes, number of thumbnails, etc. In this example I have set a limit of 9 to the thumbnails. At the bottom of the page, near the top of the script, it looks like:</p>
<pre class="brush: xml;">

numThumbs: 9,
</pre>
<h2>Set up your style</h2>
<p>I have created a master style sheet that incorporates some of the Textpattern defaults as well as galleriffic specific css. Copy the content from the <strong>screen.css</strong> file provided in the Styles folder and paste it into your default styles tab under <strong>Presentation</strong> &gt; <strong>Style</strong>.</p>
<h2>Add your images</h2>
<p>Go ahead and start uploading some images, and create some thumbnails. Make sure your images are all using the same size of thumbnail. Take note of the image ID numbers, as that is what you will use to call your images into the article. Make sure to add the <strong>Alt text</strong> and <strong>Caption </strong>when you upload, as this is what will appear to the left of the main image (unless you opted to delete the captions).<br />
<img class="alignnone size-full wp-image-639" title="caption" src="http://fuelyourcoding.com/files/caption.jpg" alt="caption" width="549" height="390" /></p>
<p>Create a new article called <strong>gallery</strong>. On the left hand side, click <strong>advanced options</strong>, and enter the ID numbers of the images you want to appear in the gallery, separated by commas. Make sure you post the article to the <strong>gallery</strong> section, or whichever section you have set up to display the gallery, and click publish. Your article should look something like this:</p>
<p><img class="alignnone size-full wp-image-638" title="article_image" src="http://fuelyourcoding.com/files/article_image.jpg" alt="article_image" width="606" height="415" /></p>
<p><strong>View Site.</strong> You should notice that the images have been automatically formatted into thumbnails on the left, with the first one appearing in full on the right. That&#8217;s it! You have a galleriffic gallery integrated with Textpattern. Play around with the html, settings, scripts and CSS to customize it to suit your own needs.</p>
<p>If you have any questions, suggestions, or requests for future articles, please do not hesitate to leave a comment.</p>
<p>Thanks, and happy coding!</p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/easy-to-update-thumbnail-gallery-using-textpattern-and-galleriffic/">Easy to update thumbnail gallery using Textpattern and Galleriffic</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/easy-to-update-thumbnail-gallery-using-textpattern-and-galleriffic/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Roll Your Own PHP Framework: Part II</title>
		<link>http://fuelyourcoding.com/roll-your-own-php-framework-part-ii/</link>
		<comments>http://fuelyourcoding.com/roll-your-own-php-framework-part-ii/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 13:03:35 +0000</pubDate>
		<dc:creator>Wess Cope</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[training]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=623</guid>
		<description><![CDATA[A little over a week ago, we looked at how to set up our file structure and how to get URL routing working in our little framework. So we now have something to handle urls and display a page, but we want to make the page a little more attractive. Since there is nothing fun [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/roll-your-own-php-framework-part-ii/">Roll Your Own PHP Framework: Part II</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://fuelyourcoding.com/php-frameworks-just-roll-your-own-part-1/">A little over a week ago</a>, we looked at how to set up our file structure and how to get URL routing working in our little framework. So we now have something to handle urls and display a page, but we want to make the page a little more attractive. Since there is nothing fun about making php print html, let&#8217;s add a template piece to the puzzle. We won&#8217;t have to do too much since php is a great template language by itself. </p>
<p><strong>Mini-series Overview</strong></p>
<ul>
<li><a href="http://fuelyourcoding.com/php-frameworks-just-roll-your-own-part-1/">Part 1: URL Routing and Directory Setup</a></li>
<li>Part 2: Templating</li>
<li>Part 3: Database Interaction</li>
</ul>
<p><em>Note: I&#8217;m assuming you have a little OOP (Object Oriented Programming) experience.  There are a ton of tutorials out there, so just a heads up:  I won&#8217;t be teaching/explaining OOP here.</em></p>
<p>We are going to create a class <tt>Template</tt> and add a little code to it so it will return our pretty new page to our browser.</p>
<p>Wipe out <tt>system/template.php</tt> and add the following code to it:</p>
<pre class="brush: php;">
&lt;?php
// We are creating a simple class here to handle our templating.
// All this class will do is set some variables and return
// a rendered webpage using native php as the template language.
class Template
{
	// We setup $pageVars to hold all our pages
	// variables.
	private $pageVars = array();

	// We setup $template to define what file is our
	// template and were to get it.
	private $template;

	// When a new Template object is instantiated we want to make sure
	// we pass it a shortened path to the file we want it to use
	// as our template.
	// example: $template = new Template(&quot;helloworld/templates/helloworld.php&quot;);

	public function __construct($template)
	{

		// We setup our action directory
		$actionsDirectory = PEANUT_ROOT_DIR . 'actions';

		// Let's build and set our class var $template to the
		// value of $template that was passed into our __construct method
		$this-&gt;template = $actionsDirectory . '/' . $template;
	}

	// Now we create out set method to allow use to set variables that
	// we want in the template.
	// So in our page action we would do:
	// $template-&gt;set(&quot;title&quot;, &quot;hello world&quot;);
	// and in our template:
	// &lt;h1&gt;&lt;?php echo $title; ?&gt;&lt;/h1&gt;
	public function set($var, $val)
	{
		// This may look weird, but it's not to bad;
		// what we are doing is setting the index name
		// of our associative array pageVars
		// (we setup earlier at the top of the class)
		// to the value that we pass. so $pageVars[&quot;yourVar&quot;] = &quot;yourValue&quot;
		// is basically what it's doing.
		$this-&gt;pageVars[$var] = $val;
	}

	// To render we will need to do a couple of things.
	// First we will need to extract those pageVars then
	// include the template, populate the values in the template
	// and return a rendered page to the browser
	//
	// This is far more easy than you think it is
	// trust me!
	public function render()
	{
		// The extract function is a weird bird
		// when you call it on an associative array
		// it creates regular vars.
		// For instance:
		// 		$this-&gt;pageVars[&quot;yourVar&quot;]
		// becomes:
		// 		$yourVar
		// so basically we are converting all the
		// index keys (with their values), in pageVars to
		// their own respected variables
		extract($this-&gt;pageVars);

		// Now that we have all the variables extracted, the vars we set
		// in the template will be replaced by the value of the pageVars variables.
		// Now we start up our output buffer, grab our template and return the
		// buffer with it's &quot;rendered&quot; template
		ob_start();
			require($this-&gt;template);
		return ob_get_clean();
	}
}
</pre>
<p>Well hello templating! Now let&#8217;s do a couple of things to hook it up to our framework. First, let&#8217;s open up our <tt>www/index.php</tt> one more time and add the following line:</p>
<p>	require(PEANUT_ROOT_DIR . &#8217;system/template.php&#8217;);</p>
<p>Right underneath the <tt>dispatch.php</tt> require statement. Now let&#8217;s change our <tt>actions/helloworld/actions.php</tt> <tt>mypage</tt> function to look like:</p>
<pre class="brush: php;">
// We simply define the function (the second item in our request url)
// making sure it is the same name as the one in the url.
function mypage()
{
	// Let's create a new template object and pass it the path to our template
	$template = new Template(&quot;helloworld/templates/helloworld.php&quot;);

	// Set our page variable &quot;title&quot; with the value &quot;Hello World&quot;
	$template-&gt;set('title', 'Hello World');

	// Set our page variable &quot;message&quot; with our little message
	$template-&gt;set('message','This is my first message for my template');

	// Now we can call render and return it to dispatch to
	// display in our browser
	return $template-&gt;render();
}
</pre>
<p>Ok, so now our page action is setup to use our new found template class, now we need to setup our template</p>
<p>So inside actions/helloworld/templates/helloworld.php template put the following:</p>
<pre class="brush: xml;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;meta http-equiv=&quot;Content-type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
		&lt;title&gt;My PEANUT Page&lt;/title&gt;

	&lt;/head&gt;
	&lt;body&gt;
		&lt;!--
		See how we use native php here?
		echo out a variable, this is the same
		variable name that you use in your template
		set method ($template-&gt;('title', &quot;hello&quot;)).
		--&gt;
		&lt;h1&gt;&lt;?php echo $title ?&gt;&lt;/h1&gt;
		&lt;p&gt;&lt;?php echo $message ?&gt;&lt;/p&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Ok, so let&#8217;s see where we are at.  We have basic url routing, templating, and page actions.  We are only missing one thing, a way to talk to the database! That will be the next and final article in our mini-series on rolling your own PHP Framework.</p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/roll-your-own-php-framework-part-ii/">Roll Your Own PHP Framework: Part II</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/roll-your-own-php-framework-part-ii/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>PHP Frameworks? Just roll your own! &#8211; PART 1</title>
		<link>http://fuelyourcoding.com/php-frameworks-just-roll-your-own-part-1/</link>
		<comments>http://fuelyourcoding.com/php-frameworks-just-roll-your-own-part-1/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 12:13:01 +0000</pubDate>
		<dc:creator>Wess Cope</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[concept]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[url routing]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=601</guid>
		<description><![CDATA[There are quite a few php frameworks out there.  Some huge, some small; Some useful, some not.  I often hear developers, even myself, complain about frameworks in php not having or not doing something the way they/we want it too.  So my solution? Roll your own framework! This series of articles is [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/php-frameworks-just-roll-your-own-part-1/">PHP Frameworks? Just roll your own! &#8211; PART 1</a></p>
]]></description>
			<content:encoded><![CDATA[<p>There are quite a few php frameworks out there.  Some huge, some small; Some useful, some not.  I often hear developers, even myself, complain about frameworks in php not having or not doing something the way they/we want it too.  So my solution? Roll your own framework! This series of articles is going to give you a brief and quick intro on how to do just that.  We are going to cover url routing, basic database connection, basic templating and basic rewrite rules for Apache.  What we will not cover is ORM development, advanced routing and installation of LAMP (Linux, Apache, MySQL, PHP). Also error checking will be next to none as this is just an example.</p>
<p><strong>Mini-series Overview</strong></p>
<ul>
<li>Week 1: URL Routing and Directory Setup</li>
<li>Week 2: Templating</li>
<li>Week 3: Database Interaction</li>
</ul>
<p>To get started let&#8217;s setup our directory structure.  We are going to call our framework &#8220;Peanut&#8221; (first thing that popped in my head).<br />
So for our structure let&#8217;s make it really basic:</p>
<pre>
MyWebApp/
  '---actions/
    '---helloworld/
      '--- actions.php
      '--- models.php
      '--- templates/
        '--- yourTemplateHere.php
'---system/
  '--- template.php
  '--- database.php
  '--- dispatch.php
'---www/
  '--- js/
  '--- css/
  '--- images/
  '--- index.php
</pre>
<p>Let&#8217;s break this structure down, it&#8217;s simple.  </p>
<p>MyWebApp: the root of your web app that will be using our &#8220;Peanut&#8221; framework</p>
<ul>
<li>actions: this will contain all the pages our web app will use.
<ul>
<li>helloworld: is the name of our page action or &#8217;section&#8217; of our site
<ul>
<li>actions.php: is where we will code our page actions</li>
<li>models.php: where we will write all our database interaction</li>
<li>templates: this is the folder we will store all our views/templates</li>
</ul>
</li>
</ul>
</li>
<li>system: this is where we will store all our framework specific classes/source/libraries
<ul>
<li>template.php: This will handle all of our template rendering.</li>
<li>database.php: This is for our database connection and access</li>
<li>dispatch.php: This will parse our url and call the correct page action.</li>
</ul>
</li>
<li>www: this is our root web directory, it is also where we will pull everything together.
<ul>
<li>js: the directory where you store your javascript</li>
<li>css: put your style sheets in here</li>
<li>images: guess!</li>
<li>index.php: This is the file that will initiate and pull together the pieces of Peanut.</li>
</ul>
</li>
</ul>
<p>Now that we have a directory structure, let&#8217;s setup a virtual host in Apache to accommodate for Peanut. Here is an example of a virtual host you can use (here is what I do on my Mac):</p>
<pre class="brush: plain;">
NameVirtualHost *:80

&lt;VirtualHost *:80&gt;
        ServerName      mywebapp.local
        DocumentRoot    /Users/wcope/Sites/mywebapp/www

        AcceptPathInfo On

        RewriteEngine On
        RewriteRule     /*\.(css|js|gif|png|jpe?g)$ - [NC,L]
        RewriteRule &quot;^(.*)$&quot;    &quot;/index.php?_url=$1&quot; [QSA,L]

        &lt;Directory &quot;/Users/wcope/Sites/mywebapp/www&quot;&gt;
                AllowOverride All
                Order allow,deny
                Allow from all
        &lt;/Directory&gt;

&lt;/VirtualHost&gt;
</pre>
<p>And In my /etc/hosts file I add this line:</p>
<pre class="brush: plain;">
127.0.0.1	mywebapp.local
</pre>
<p>That will allow &#8216;mywebapp.local&#8217; to resolve to my localhost where Apache will pick it up and kick it off to the virtual host we created. Inside that virtual host we have some rewrite rules that will redirect all request made (except css, js, gif, png, jpeg/jpg) to index.php?_url=$1.  To break that down in the simplest way, basically Apache takes: mywebapp.local/some/page and redirects it to index.php?_url=/some/page (but you never see the latter). Also notice that we made the root directory of our virtual host to our www folder where index.php is.</p>
<p>Ok, so now we have our directory structure, virtual host and rewrite rules all setup.  If you have any detailed questions about Apache, mod_rewrite, virtual hosts, host files, etc. Sorry they will not be covered here due to the fact that there is tons on it out there&#8230; so hit up your local <a href="http://google.com"> google.com</a> :). </p>
<p>So now let&#8217;s get to some code.</p>
<p>So first lets write our dispatch code since that will be what is responsible for routing all our request to the proper pages.</p>
<p>Open up <tt>index.php</tt> in your favorite text editor and let&#8217;s slap some code in it:</p>
<p>In this file is a good place to put constant variables, include any files and call our dispatch (once we write it). But for right now let&#8217;s do a little test, and also write a little helper function I&#8217;m going to use to print stuff to the screen that can help us see what&#8217;s going on.</p>
<pre class="brush: php;">
&lt;?php
// First let's define our apps root directory
define(&quot;PEANUT_ROOT_DIR&quot;, realpath(dirname(__FILE__) . '/../') . '/');

// now a pretty little dump function (or if you have xdebug you can just use var_dump)
function dump($item, $die=true)
{
	$printString = '&lt;pre&gt;' . print_r($item, true) . '&lt;/pre&gt;';
	if($die)
		die($printString);
	else
		echo $printString;
}

// Now let's just dump our URL to make sure that all paths lead here
dump($_GET);
?&gt;
</pre>
<p>Now if we bring up our url: http://mywebapp.local/some/url/ we should see something like:</p>
<pre class="brush: php;">
Array
(
    [_url] =&gt; /some/url/
)
</pre>
<p>So now we can see that our rewrite is working and we are ready to start writing our dispatch function, so let&#8217;s change our index.php code a little.</p>
<pre class="brush: php;">
&lt;?php
// First let's define our apps root directory
define(&quot;PEANUT_ROOT_DIR&quot;, realpath(dirname(__FILE__) . '/../') . '/');

// now a pretty little dump function (or if you have xdebug you can just use var_dump)
function dump($item, $die=true)
{
	$printString = '&lt;pre&gt;' . print_r($item, true) . '&lt;/pre&gt;';
	if($die)
		die($printString);
	else
		echo $printString;
}

// Let's comment this out
// dump($_GET);
// and add this:

// first we are going to drop our dispatch file in here
require(PEANUT_ROOT_DIR . 'system/dispatch.php');

// then call our dispatch function to handle the url
// Notice Im not passing in $_GET or $_GET['_url'], being that
// $_GET is a global system variable, I don't have to worry about it
// here.

dispatch();
?&gt;
</pre>
<p>So now let&#8217;s save that and crack open our system/dispatch.php file and and add some code to it to handle our new found url pattern.  As I said before, this will only be a simple router with no config or predefined url pattern to page action mapping.</p>
<p>So, inside dispatch.php, let&#8217;s add:</p>
<pre class="brush: php;">
&lt;?php
// Here we are going to handle our url request

function dispatch()
{
	// First we are going to grab our url path and trim the / of the
	// left and the right
	$url = trim($_GET['_url'], '/');

	// Now we are going to split the url on the / which
	// will give us an array with 2 indexes.
	$url = explode('/', $url);

	// Let's just print out our array to get a visual of
	// what we are working with.
	dump($url);
}

?&gt;
</pre>
<p>Now if you refresh your browser at our current url (http://mywebapp.local/some/url/) you should see:</p>
<pre class="brush: php;">
Array
(
    [0] =&gt; some
    [1] =&gt; url
)
</pre>
<p>Great, now we have 2 clean items to work with.  So let&#8217;s tell dispatch that the item at index 0 will be our folder and item at 1 will be the page action inside our actions.php file.  Since our directory structure is setup to use <tt>actions/helloworld/actions.php</tt>, let&#8217;s setup dispatch to include the file with our action in it in the directory that was requested in the url.  So change dispatch.php to look like:</p>
<pre class="brush: php;">
// Let's handle that url
function dispatch()
{
	// First we are going to grab the url path and trim the / off
	// the left and the right.
	$url = trim($_GET['_url'], '/');

	// We changed this from before to make it easier to read and also so we can
	// work with easier variables.  using the list (http://php.net/list) function
	// will map the array indexes to the respected order of the var names inside
	// the list function call (better explanation at php.net/lists).
	list($directory, $action) = explode('/', $url);

	// Now we drop in our respected actions file from the directory in the url
	require(PEANUT_ROOT_DIR . 'actions/' . $directory . '/actions.php');

	// And call the action from inside our actions.php file
	// and since we want to end our request with the return value of our requested method
	// let's just die on the return.
	die($action());
}
</pre>
<p>Now we need to add our action inside our actions.php file, so open it up and drop the following<br />
in it:</p>
<pre class="brush: php;">
&lt;?php

// We simply define the function (the second item in our request url)
// making sure it is the same name as the one in the url.
function mypage()
{
	// For now we are simply going to return &quot;Hello World&quot; string
	return &quot;Hello World&quot;;
}

?&gt;
</pre>
<p>So let&#8217;s give this a shot.  Open up your web browser and point it to: http://mywebapp.local/helloworld/mypage.You should see a pretty little &#8220;Hello World&#8221; in the browser. If you do, congrats! You now have routing in your new Peanut framework.  </p>
<p>Next week we will see how to add templating into our framework.</p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/php-frameworks-just-roll-your-own-part-1/">PHP Frameworks? Just roll your own! &#8211; PART 1</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/php-frameworks-just-roll-your-own-part-1/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Getting Started with Chyrp</title>
		<link>http://fuelyourcoding.com/getting-started-with-chyrp/</link>
		<comments>http://fuelyourcoding.com/getting-started-with-chyrp/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 20:38:21 +0000</pubDate>
		<dc:creator>Ethan Turkeltaub</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[chyrp]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[walkthrough]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=473</guid>
		<description><![CDATA[Instead of using chunky, slow ol' Wordpress, why not use the simpler, faster, solution: Chyrp?<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/getting-started-with-chyrp/">Getting Started with Chyrp</a></p>
]]></description>
			<content:encoded><![CDATA[<p><!-- introduction --></p>
<h2>Introduction</h2>
<p>In the world of web development, when building a blog, you don&#8217;t always want to refer to a slow, over-featured blogging engine like Wordpress. Thankfully, there is a solution, and its name is <a href="http://www.chyrp.net/">Chyrp</a>. Chyrp is a blogging engine that is designed to be extremely lightweight, while still retaining functionality. Alex Suraci, the developer behind Chyrp, codes it in Twig, a language specifically created for this project. The Twig is then put through a compiler and its output is solid PHP.</p>
<p>Before we start, it is important to know how Chyrp is extended: Feathers extend post formats, Modules add functionality, such as a commenting system, and Themes change the look and feel. Keep this in mind.</p>
<p>Interested? Well then, let&#8217;s get started!</p>
<p><img class="alignnone size-medium wp-image-477" src="http://fuelyourcoding.com/files/chyrp1-600x320.jpg" alt="chyrp1" width="600" height="320" /></p>
<h2>Installation</h2>
<p><a href="http://www.chyrp.net/" target="_blank">Download Chyrp</a>, and open up the folder Chyrp v2.0, which should be in the same directory as the archive. Select all the contents and copy and paste it to a directory on your web server (for the purposes of this article, we&#8217;ll be using the /chyrp/ directory). Now would be the time to read the COPYING file, so you don&#8217;t break any copyright laws. You can delete it or keep it, along with the README.markdown file. If your server isn&#8217;t already started, start it. Go to http://localhost/chyrp/ (Or whatever address you use to access your testing server) in your web browser and you should have two errors at the top of the browser window: one for the .htaccess file, and the other for permissions.</p>
<p><img class="alignnone size-medium wp-image-480" src="http://fuelyourcoding.com/files/chyrp4-600x347.jpg" alt="chyrp4" width="600" height="347" /></p>
<p>Go ahead and create the .htaccess file with the contents it shows, and save it in the /chyrp/ directory. You also need to CHMOD the /chyrp/includes/ directory to 777. This means changing the permissions to all read and write. Once you&#8217;ve done that, refresh the web browser page. Now, go ahead and fill in your database information. In this article, we&#8217;ll be using MySQL.</p>
<p>Back at the installation screen, insert your database information. The host is usually localhost. As for a table prefix, we can leave that blank, unless we&#8217;re installing multiple instances of Chyrp on the same database.</p>
<p>Once you filled out the form, hit Install. It fills the database with the information and configures the files within the instance. When it is complete, this page will show:</p>
<p><img class="alignnone size-medium wp-image-478" src="http://fuelyourcoding.com/files/chyrp9-600x344.jpg" alt="chyrp9" width="600" height="344" /></p>
<p>So, delete install.php within /chyrp/, as it poses a security risk if you keep it. If you speak German, you&#8217;re in lucky, because that is the only language pack available at the moment. So now, click Take me to my site! and you&#8217;ll be taken to the home page.</p>
<p>As you can see, there are no posts. Go to the sidebar and click Login, and use your credentials from before. Once that is done, a toolbar will appear in the top. Click the Admin link and you&#8217;ll be taken to the backend.</p>
<h2>Writing in Chyrp</h2>
<p>When you open the backend (it is located at /chyrp/admin/), the Write section is automatically visible. And because Chyrp is a blogging engine, you can make posts and pages. Posts can come in many different forms, such as photos, videos, and plain old text. These different forms come in extensions called Feathers. If you add a photo, you&#8217;ll need the photo Feather in order to do that. The text Feather already comes with Chyrp, and is already activated. The photo, video, link, audio, quote, and chat Feathers already come with the installation, but are not yet activated. We&#8217;ll go through activating them later.</p>
<p>To create a post or page, just select the type on the tabs and type up what you&#8217;d like to say. If you click More Options you can choose a permission status, slug, trackback, timestamp, and pinned status (whether or not you&#8217;d like it as first post, no matter what). Once you&#8217;re done, you can save it, or Publish it. Once you hit Publish, Chyrp will take you to the home page, where you can view your post. It&#8217;s just that easy!</p>
<h2>Manage your Install</h2>
<p>Head back to the backend and click on the Manage tab, near the top. This will bring you to this page:</p>
<p><img class="alignnone size-medium wp-image-481" src="http://fuelyourcoding.com/files/chyrp12-600x287.jpg" alt="chyrp12" width="600" height="287" /></p>
<p>From here you can manage everything about your install. If you click one of the tabs near the middle of the page, you can select what you want to manage. As you add Modules, more tabs will appear.</p>
<p>Modules are ways to extend your install. For example, one Module creates a commenting system, and another allows you to cache pages. We&#8217;ll get into this later.</p>
<p>What you need to focus on in the Manage section is the Groups tab. This allows you to change permissions for groups. Currently, you are part of the Admin group. Click on the edit link (it&#8217;s on the right side) and you&#8217;ll be taken to the page for editing group permissions, as well as the name of the group. Click Save when you&#8217;re done.</p>
<h2>Change the Settings</h2>
<p>The next navigation option is Settings. Under General, you can change your blogs&#8217; name, description, and other settings. Under Content, you can edit posts per page, uploads path, and allowing XML-RPC support. Then, in Users, you can allow r disallow users registering themselves, the default user group, and what group Guests are in (you can even allow all un-registered guests to have Admin permissions, though it is not suggested). Finally, under Routes, you can allow clean URL&#8217;s, which will make the URL&#8217;s formatted as stated in the form below (I highly recommend it—who wants a URL with a question mark in it?).</p>
<h2>Extending your Install</h2>
<p>The Extend section is very important. Extensions are what make Chyrp so very powerful and functional. Modules are very powerful, and the ones that are made by the head developer come with Chyrp. Those are:</p>
<ul>
<li>Textilize</li>
<li>SWFUpload</li>
<li>Paging</li>
<li>Aggregator</li>
<li>Tagginator</li>
<li>Read More</li>
<li>Comment System</li>
<li>Markdown</li>
<li>SmartyPants</li>
<li>Cacher</li>
</ul>
<p><img class="alignnone size-medium wp-image-479" src="http://fuelyourcoding.com/files/chyrp13-600x295.jpg" alt="chyrp13" width="600" height="295" /></p>
<p>All these do exactly what they&#8217;re named for. To activate them, just drag it from the red zone into the green zone. When you do that, a dialog pops up, reminding you to change the permissions. Once you&#8217;ve added all the Modules you want, go back into Manage &gt; Groups and change the permissions so you can manage the Modules.</p>
<p>Now, go ahead and go into the Feathers section. As you can see, the following Feathers come with Chyrp:</p>
<ul>
<li>Photo</li>
<li>Video</li>
<li>Link</li>
<li>Audio</li>
<li>Quote</li>
<li>Chat</li>
</ul>
<p>Plus, the Text Feather, but it is already activated. To activate them, it is the same action as before. If you enable the Photo, Video, or Audio Feather, then you need to create a uploads directory in /chyrp/ and CHMOD it to 777 so you can upload media.</p>
<p>And finally, Themes. The theme that comes with Chyrp is called Stardust. It may be fine for a casual blogger, but for a designer, like me, you need to design your own. That will be in a follow-up article.</p>
<h2>Downloading Extensions</h2>
<p>There are some more extensions on the Chyrp site. There are not many, but the user base is growing rapidly, and so is the development base. To add Feathers, Modules, Themes, etc, just download it and extract the archive to /themes/, /modules/, or /feathers/, respectively. Then, just go into the backend and activate it. It&#8217;s just that simple.</p>
<h2>Chyrp vs. Wordpress</h2>
<p>You may be questioning, “Why Chyrp? Why not just go with the popular solution: Wordpress?” Well, why Wordpress? There are a lot of functions in Wordpress that you&#8217;ll never need or use, so why have them. A fresh Chyrp install is bare bones, and you&#8217;re free to install what you need. Plus, Chyrp is a lot faster than Wordpress, on the front and backend.</p>
<p>As well as speed, Chyrp has better code than Wordpress—Alex (founder and sole core-developer) uses Ruby on Rails and Python helpers to have perfect code that is easy to edit.</p>
<p>While retaining functionality, Chyrp is more flexible than Wordpress. It can do a lot of different functions, and is easy to mod to your hearts content.</p>
<p>So why use Wordpress?</p>
<h2>The Chyrp Community and Support</h2>
<p>Chyrp has a strong community and support group. In the <a href="http://www.chyrp.net/discuss">Discuss section of the Chyrp site</a>, you can ask for help or just discuss&#8230; whatever. Or, to get instant help, log on to good ol&#8217; IRC on irc://freenode.org/chyrp (that would be irc.freenode.org as the server, then #chyrp as the channel).</p>
<p><!-- /support --></p>
<p>In the next article, we&#8217;ll be building a custom theme!</p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/getting-started-with-chyrp/">Getting Started with Chyrp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/getting-started-with-chyrp/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>A Few Strategies for Using JavaScript</title>
		<link>http://fuelyourcoding.com/a-few-strategies-for-using-javascript/</link>
		<comments>http://fuelyourcoding.com/a-few-strategies-for-using-javascript/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 20:42:51 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[stragies]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=404</guid>
		<description><![CDATA[The primary use for JavaScript in web pages is to enhance or add functionality not present in a static web page. If used correctly, this can be a great asset to a skilled developer. Used incorrectly, you (and your users) will be in for all sorts of nightmares.
Before we get to the good strategies, here [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/a-few-strategies-for-using-javascript/">A Few Strategies for Using JavaScript</a></p>
]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight: normal; font-size: 13px; ">The primary use for JavaScript in web pages is to enhance or add functionality not present in a static web page. If used correctly, this can be a great asset to a skilled developer. Used incorrectly, you (and your users) will be in for all sorts of nightmares.</span></p>
<p>Before we get to the good strategies, here are three things NOT to do.</p>
<h2>Don’t Use JavaScript&#8230;</h2>
<p><strong></strong><strong>To add information that needs to be indexed by search engines.<br />
<span style="font-weight: normal;">This is a no brainer, but still easy to overlook. We try so hard to have lean and mean HTML that we can be tempted to move indexable information into javascript vs. keeping in the HTML. If the search engines need to see it, leave it in the HTML.</span></strong></p>
<p><strong></strong><strong>To fix things you are too lazy to fix in the source.<br />
<span style="font-weight: normal;">If you have the opportunity to apply a fix, move the elements around, or otherwise achieve your end result without using JavaScript, do it. There is a performance hit realized with editing the DOM with JavaScript. Only use it if it makes sense.</span></strong></p>
<p><strong></strong><strong>Primarily to make a site “cool”</strong><br />
I could reverse the statement to read “Only use JavaScript to enhance the user experience, provide appropriate indicators to the user, and improve the overall usability of the site.” Or, in more cliched terms, &#8220;JavaScript Responsibly&#8221;. There are tons of things you <strong>can</strong> do, but be sure only tackle the things you <strong>should</strong> do.</p>
<h2>Good Strategies</h2>
<h3>Choosing a Good Framework (or Not)</h3>
<p><strong>Should Beginner JavaScript Programmers Use a Framework?</strong><br />
There are currently many strong Frameworks and Libraries for JavaScript. <a href="http://www.prototypejs.org">Prototype</a>, <a href="http://www.mootools.net">MooTools</a>, and <a href="http://www.jquery.com">jQuery</a> are just a few. The question then is asked, “Should you learn straight JavaScript first, or start with one of these frameworks?” Though JavaScript syntax and best practices are super important, I would argue that you should start with a Framework if all you plan to do is enhance your web pages. This is often the simplest to learn, and you won&#8217;t have to waste time on browser differences in how they handle common functions (Think XMLHTTPRequest). If you plan on developing advanced AJAX/DHTML front-ends, then learning how to manipulate the DOM, make AJAX requests, etc using only JavaScript would be a good idea. If you want to build plugins for your Framework of choice, then it is also a good idea to understand what is happening behind the scenes.</p>
<p><strong>A Framework May Make Maintenance Easier<br />
<span style="font-weight: normal;">Its pretty short-sighted to assume you will be the only one maintaining or editing your code down the road. Your business may grow, your clients may move to another developer, etc. Its due to the idea of group editing that I suggest the use of a solid Framework. If you use a framework, and use it correctly (Doing it the &#8220;right way&#8221;), other people picking up your code should have an easier time finding out what is going on.</span></strong></p>
<p><strong>Know When To Avoid Using a Framework<br />
<span style="font-weight: normal;">There are many situations where using a Framework becomes impractical. If all you need to do is show or hide a single element on a page, use straight JS. Its not worth the 50k+ overhead to load the Framework. If you are building a widget for inclusion on another site, don&#8217;t use a Framework. As an example, <a href="http://www.foxycart.com">FoxyCart</a> is a super easy to use cart system that uses JavaScript to power their cart. A problem you will run into when using FoxyCart, however, is that they include their own copy of jQuery. As a widget/library that is embedded on someone else&#8217;s site, they should have coded their library by hand to avoid conflicts with other libraries. (For you jQuery people out there, using $.noConflict doesn&#8217;t fix problems with two copies of jQuery running on the same site).</span></strong></p>
<h3>Fixing Element Jumps</h3>
<p>If there are a lot of elements on the page that apply specifically to a JavaScript context, you may see elements jump around, or appear then disappear when the JavaScript finally loads. There are many different situations where this could be a problem, but here are some strategies for avoiding it. This is often more of a problem if you put your JavaScript files at the bottom of the page (As you should).</p>
<p><strong>Use Special CSS Classes<br />
</strong>I like to add a <tt>no_js</tt> class to elements I intend to enhance with javascript. Style the elements in your javascript file using the <tt>.no_js</tt> class for how they should appear when either JavaScript is disabled, or it hasn&#8217;t loaded yet. Have the last step of your JavaScript setup be to remove that class from the elements.</p>
<p><strong>Start Editing Earlier<br />
</strong>If you use a JavaScript Framework (like MooTools or jQuery) be sure to utilize their DOM Ready functions instead of onLoad. The DOM will often be ready far before everything has fully loaded and may afford you the extra time you need.</p>
<p><strong>Add JavaScript Specific Elements with JavaScript<br />
<span style="font-weight: normal; ">If an HTML element&#8217;s only value is realized when JavaScript is in use, then add it dynamically with Javascript. For example, you don&#8217;t want an empty div#overlay just sitting at the end of your HTML. Just add it with JavaScript.</span></strong></p>
<h3>Debugging</h3>
<p><strong>Use Firebug and console.log</strong><br />
In a tiny script, dropping in <tt>alert('Here!')</tt> might work OK. However, when doing anything larger, you will want to utilize the <a href="http://www.getfirebug.com">Firebug</a> console for testing and debugging. Use it to output values and objects, and even DOM objects. It will often provide quick insight and let you solve problems faster.</p>
<p><strong>Don&#8217;t forget to remove console.log Statements<br />
<span style="font-weight: normal; ">If you use Firebug, be sure to remove <tt>console.log</tt> statements, or provide another way to avoid missing method errors. This one has caught me so many times: It works on my computer, but not on the client&#8217;s computer. We are both using Firefox. To add to the confusion, the site functions fine in Safari too. What is wrong !!? Ah! It’s the remaining console.log statements I used for debugging! Safari will often just skip the statements without complaining much, so BE SURE to search for &#8220;console.log&#8221; and remove the statements before deploying (or showing a comp to the client).</span></strong></p>
<h2><span style="font-weight: normal;">Conclusion</span></h2>
<p><span style="font-weight: normal;">I have just touched on a few strategies and tips for using JavaScript on your pages. Feel free to share your own in the comments! As I come across other useful tips in the future, I will be sure to post them to the site as well.</span></p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/a-few-strategies-for-using-javascript/">A Few Strategies for Using JavaScript</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/a-few-strategies-for-using-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>10 Rules of Front End Coding</title>
		<link>http://fuelyourcoding.com/10-rules-of-front-end-coding/</link>
		<comments>http://fuelyourcoding.com/10-rules-of-front-end-coding/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 20:45:00 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[rules]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=266</guid>
		<description><![CDATA[What follows here is a series of 10 things to remember and practice on each web development project. I have listed them here in order of importance as many of the steps build on each other. If you take nothing else away from the reading, please take Rules #1 and #2 to heart and practice [...]<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/10-rules-of-front-end-coding/">10 Rules of Front End Coding</a></p>
]]></description>
			<content:encoded><![CDATA[<p>What follows here is a series of 10 things to remember and practice on each web development project. I have listed them here in order of importance as many of the steps build on each other. If you take nothing else away from the reading, please take Rules #1 and #2 to heart and practice them. I think solving those two problems will lead to better design and better implementation in websites across the Internet.</p>
<h2>1. Charge Enough, and Then Some</h2>
<p>Especially in hard economic times, business and individuals alike are trying to cut costs and keep projects down to a minimum. Due to this knowledge, we as web developers try to move through each phase as quickly as possible. Front end development, however, take a substantial amount of time if done properly. Not adequately charging for that time leads us as developers to <em>skip over things we know are important</em> just to keep the project within the budget. The rule is simple&#8230; you normally won&#8217;t take the time to do it right if you don&#8217;t have the time to take. The only way to get more &#8220;time&#8221; as a developer, is to guarantee the time we DO spend is properly compensated. At that point alone can our hearts and minds be fully plugged into our projects&#8230; and only then can we take the time to follow the remaining 9 rules.</p>
<h2>2. Educate The Designer</h2>
<p>For those who are a designer/developer all-in-one machine, this one should be easy. However, coders who work with or for a designer have a unique responsibility. As many designers come from a print background, it is up to you, the developer, to educate them on the possibilities available to their designs. No&#8230; I didn&#8217;t say let them know about the 150+ jQuery plugins you use, or your thoughts on using a UL/LI combo vs a series of A tags. I said educate them to the possibilities. Help them understand how their design might display on different devices. Help them understand how to leverage repeating backgrounds and tiled patterns to achieve great designs with minimum file size.</p>
<p>Don&#8217;t leave the creativity solely to the designer either! This is your chance to prove you are creative as well by finding the perfect technology solutions to meet the needs of the designer. Telling them &#8220;it just isn&#8217;t done that way&#8221; for every request is a sure-fire way to cause frustrations on both sides. Put your mind to work finding ways around hurdles.</p>
<p><em>Note: Rules 3 through 10 build off these first two rules. Some of the following rules require additional graphics from the designer, and all the rules take time to follow. Make a commitment to rules 1 and 2, and the remaining rules will both make sense and make your finished product that much better.</em></p>
<h2>3. Think in Layers, Not in Slices</h2>
<p>Even today, we still use the phrase “cut up the design” to describe the process of moving a design from Illustrator or Photoshop into the finished HTML/CSS layout. While this is still largely accurate, its name belies the former concept of slicing a design into pieces and reassembling it (usually in a table) back on the HTML page.</p>
<p>That was the old web. The new web uses the concept of layering, stacking, and z-index to achieve designs with depth. As a coder, be sure to get layered PSD files or layered AI files from the designer vs. a flat design. This will allow you to have much more flexibility in how you put together a web site. Remember, when working in layers, consider the HTML elements that are essential to the structure before resorting to adding additional divs and spans. You can use a repeating vertical pattern on the <code>html</code> element, and a repeating horizontal background on the <code>body</code> element without bringing the dreaded <code>div#wrapper</code> in to solve your background woes.</p>
<h2>4. Use the Best Image Format</h2>
<p>What is the &#8220;Best Image Format&#8221; you ask? It’s the one that is best suited to the task at hand. PNG, GIF, and JPEG files all have different advantages. When there is no transparency in an image, test out which file size/image quality is best between PNG, GIF and JPEG. For large images, JPEG will almost always win for quality vs size. For small images without transparency, see which has a better file size PNG or GIF. If you decide on a GIF, be sure to play with the dither options and the lossy options (Did you even know Photoshop has a &#8220;lossy&#8221; option for GIF?). Often you can squeeze even smaller files out of Photoshop through adjusting the output settings even further.</p>
<p>For images that need to have transparency, make educated decisions on how they will be used. If they will be layered over a complex background, you may need to consider using a PNG file. If the background is consistent enough that the color matte of a GIF won&#8217;t stand out poorly, see if the GIF file is smaller. GIF has the advantage of not needing additional programming to make it work in IE6.</p>
<p>Regarding JPEG use: If you use JPEG as part of your user interface (and not just to display a photo, etc) be sure to leave off the ICC profiles when saving for web. Certain browsers will honor the profile and produce a color difference between GIF/PNG and JPEG files of the same color. This is a simple problem to avoid by just turning off the ICC profiles.</p>
<p>What if it is a lose-lose situation? There have been times where I need the full transparency of a PNG with the image complexity better suited for a JPEG. In these cases I often stack (remember, think in layers) two images: a PNG for the transparency, and a GIF for the complex image aspect. It is creative problem solving like this that will ensure your pages load quickly, and that the design retains its integrity.</p>
<h2>5. Know When to Use Classes vs. Ids</h2>
<p>I thought this was just common sense, but apparently it isn&#8217;t as I see many coders using class names where they should use ids. It may not seem like a big problem, but it will when you try to target an element using Javascript.</p>
<p>The concept is simple, if there will only be one element on a given page, use an id. If there will be multiple instances on a given page, use class names. Anytime an element is one-of-a-kind, use an id. Its that simple! Things like <code>ul.navigation</code> for the main navigation bar or <code>div.site-logo</code> make no sense. Each of those elements are distinct and should have and id.</p>
<p>Instead of adding another rule to our list, let me lump something else in here: don&#8217;t use too many classes! Take the following code for an extreme example (Notice that classes appear six times):</p>
<pre class="brush: xml;">
&lt;div id=&quot;navigation&quot;&gt;
&lt;ul class=&quot;navigation-links&quot;&gt;
&lt;li class=&quot;nav-link-wrapper selected&quot;&gt;&lt;a class=&quot;nav-link&quot; ... &gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-link-wrapper&quot;&gt;&lt;a class=&quot;nav-link&quot; ... &gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>All that could be replaced with the following (A single id and a single class):</p>
<pre class="brush: xml;">
&lt;ul id=&quot;navigation&quot;&gt;
&lt;li class=&quot;selected&quot;&gt;&lt;a ... &gt; Home&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a ... &gt; Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>For those who code frequently, you realize this is a ludicrous example, but it shows the fallacy of over-using classes. <em>Use only what you need to correctly style and enhance (via Javascript) the HTML, nothing more.</em></p>
<h2>6. Make Your Pages Responsive</h2>
<p>Its important that the page responds correctly as the end user navigates through it. Using conventions like image rollover effects as well as :hover, :active and :focus states cannot be stressed enough. You don&#8217;t want to assault the user with too many interactions or styles but most people respond well to visual feedback. Here is an easy one for you: <strong>links should change state when the mouse hovers over them</strong>&#8230; <strong>period</strong>! It is not enough that the browser displays a little hand indicating a link. I can&#8217;t tell you how frustrating it is to search through a page with black text looking for the dark gray links and hoping and praying that the hand appears letting me know I found one!</p>
<p>Using conventions such as the &#8220;You are here&#8221; indicators or descriptive tool-tips all fall under this category. The more interaction and feedback that appears to the user while they navigate through a site, the better.</p>
<h2>7. Always Use CSS Sprites for Rollovers</h2>
<p>If you don&#8217;t know what CSS Sprites are, check out this article at <a href="http://www.smashingmagazine.com/2009/04/27/the-mystery-of-css-sprites-techniques-tools-and-tutorials/" target="_blank">Smashing Magazine</a> or this one at <a href="http://www.alistapart.com/articles/sprites/" target="_blank">A List Apart</a> for details. For those who DO know what they are, <strong>why don&#8217;t you use them!!?</strong> If you tell me its due to a lack of time, I want to refer you to Rule #1 in this list. Past the time argument, I can&#8217;t really think of any benefit more important than using CSS Sprites for image rollovers. Check out the <a href="http://starter.pixelgraphics.us" target="_blank">Starter for jQuery</a> site. Almost all the user interface pieces are built using a single PNG file (pictured below). The interface loads all at once, and all the hover/active states are immediately available.  No delay for a :hover image to load; One request to the server, not 10+. This a fantastic tool in the Front End Coding Toolkbox that developers need to use more frequently.</p>
<p><a href="http://starter.pixelgraphics.us/images/ui-elements.png"><img class="size-full wp-image-267 alignnone" title="UI Elements" src="http://fuelyourcoding.com/files/ui-elements.jpg" alt="Click for Full Size" width="607" height="273" /></a></p>
<h2>8. Understand the Difference Between Flash and Javascript</h2>
<p>I think Javascript can do amazing things. I also love pushing the limits of what it can do. I love making widgets and plugins just as much as the next guy&#8230; but Javascript cannot solve all the problems in dynamic web development. Instead of spending 10 hours emulating a Flash feature that would take 1 hour to make in Flash, make the right choice and choose Flash. On the other hand, if you just need an image rotator&#8230; don&#8217;t you dare open Flash!</p>
<h2>9. Test Your Site in Many Browsers (including IE6)</h2>
<p>This one takes time, there is no doubt about it. I develop on a Mac, and have a PC (and multiple Virtual PC environments) that let me test is most of the normal browsers people use today. Unless you have Google Analytics reports that say no one uses IE or everyone uses Firefox, don&#8217;t make an assumption on how people will browse your site. I am not saying make the sites look identical, but make them work, function, and look nice (And certainly similar!) in most browsers.</p>
<p><em>Note: I mention IE6 specifically because my largest client is a corporation that still uses IE6. I have developed a coding style that allows me to build rapidly for modern browsers, and implement only a few style sheet and javascript fixes so the site looks right in IE6. I am sure I lose some edge by doing it this way, but it saves me from many embarrassing moments.</em></p>
<h2>10. Always Keep Maintenance In Mind</h2>
<p>As you are &#8220;cutting up&#8221; a Photoshop design, or preparing your CSS and Javascript, keep maintenance in mind. Some crazy-cool CSS hack you use today may come back to haunt you later. Dumping CSS rules wherever you please in a CSS file may seem fast at the moment (Guilty!), but will make changing and updating them later a nightmare.</p>
<p>An important step to remember occurs after you have prepped a designer&#8217;s file for export from Photoshop or Illustrator: Remember to save a version of the file just before export. That way if you need to re-export it later, add another button, change a line of text, etc., you will be able to export it again quickly. Photoshop normally saves Image Format choices, compression settings, and matte colors to make your job even easier.</p>
<h2>Conclusion</h2>
<p>There are a number of other things that are important for Front End Coders to keep in mind, but I think these are some of the most important. Many could argue that these aren&#8217;t rules, but I challenge you to think of them as such. Perhaps you will be less likely to break them in the interest of time or money on your next project.</p>
<p><p><strong>Sponsored by</strong></p>
<a href='http://madebytinder.com' target='_blank'><img src='http://fuelbrand.s3.amazonaws.com/downloads/WhatisTinder250x250.jpg' border='0' alt='Made By Tinder' /></a>
<p><a href="http://www.fuelbrandnetwork.com/advertise/">Advertise on Fuel Brand Network</a>. <br />
  <a href="http://www.fuelbrandnetwork.com">Fuel Brand Network</a> 2010 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">cc</a> (creative commons license)
</p></p>
<p><a href="http://fuelyourcoding.com/10-rules-of-front-end-coding/">10 Rules of Front End Coding</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/10-rules-of-front-end-coding/feed/</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
	</channel>
</rss>
