<?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>3RM Design Blog &#187; Tutorials</title>
	<atom:link href="http://www.3roadsmedia.com/blog/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.3roadsmedia.com/blog</link>
	<description>Website Coding Tips &#38; Graphic Design Inspiration</description>
	<lastBuildDate>Thu, 02 Sep 2010 15:27:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Design for Letterpress</title>
		<link>http://www.3roadsmedia.com/blog/how-to-design-for-letterpress/</link>
		<comments>http://www.3roadsmedia.com/blog/how-to-design-for-letterpress/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 05:15:03 +0000</pubDate>
		<dc:creator>Brennan</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.3roadsmedia.com/blog/?p=1190</guid>
		<description><![CDATA[Letterpress can push your design to the next level, but before letting your imagination soar, it is important to know the limits and possibilities of letterpress printing. Here are some helpful tips on how to design for Letterpress. 1. Know your medium Letterpress is a wonderful, time-tested process with unique qualities. Before even beginning your [...]]]></description>
			<content:encoded><![CDATA[<p>Letterpress can push your design to the next level, but before letting your imagination soar, it is important to know the limits and possibilities of letterpress printing. Here are some helpful tips on how to design for Letterpress.<span id="more-1190"></span></p>
<h1>1. Know your medium</h1>
<p>Letterpress is a wonderful, time-tested process with unique qualities. Before even beginning your design, there are a few things to keep in mind about how Letterpress works.</p>
<h2>Letterpress is a spot color printing process</h2>
<p>When designing for Letterpress, it is important to remember that you&#8217;re dealing with a spot color printing process, and not the 4 color (CMYK) process. Where the 4 color process matches your on-screen colors by combining percentages of Cyan, Magenta, Yellow, and Black, a spot color process is very specific, <strong>using pure color rather than a mixture of CMYK</strong>. It is very important to reference your spot colors in person, and not simply rely on the on-screen rendition, as this can be vastly different from the actual Pantone color. Pick your colors in person using PMS, or the Pantone Matching System, then use those specific colors in your design (This post is written for Adobe Illustrator, but Photoshop and InDesign also contain Pantone swatches).</p>
<h2>Letterpress inks are translucent and will overlap</h2>
<p>Letterpress inks are thinned out and translucent to best work with the equipment. What does this mean for your design? If you have overlapping elements, the <strong>colors may blend</strong> unfavorably once printed. Do not overlay objects and design elements unless you want their colors to blend (you may preview this effect by switching transparency mode to &#8220;Multiply&#8221;). Of course, you can certainly use this feature to your advantage to achieve new colors without paying for additional inks.</p>
<h2>Every color is printed separately</h2>
<p>This might already be apparent based on the previous Letterpress qualities, but every color in your design will be printed separately, and you will need to separate these colors for your printer. In Illustrator, it is easy to put each color on its own layer (described later in this post). The image below shows one color of our 3 color business cards, separated into its own layer:<a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/3roads-cards-600x400_setup.jpg"><img class="alignnone size-full wp-image-1269" title="3 Roads Media Business Card, First Color" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/3roads-cards-600x400_setup.jpg" alt="" width="600" height="400" /></a></p>
<p><em>Note that photographs, full-color imagery and gradients will not print well unless you know how to separate your colors (using techniques like halftones).</em></p>
<h2>Letterpress literally &#8216;presses&#8217; your imagery</h2>
<p><strong>Letterpress always makes an </strong><em><strong>impression</strong></em><strong>.</strong> When you send a printer your separated design, every layer/color is etched onto its own metal plate. This metal plate is then coated with your specified spot color and pressed onto the paper to apply the ink, creating an impression in the process. A light impression is called a &#8220;kiss.&#8221; A deep, noticeable impression is called a &#8220;bite.&#8221; For our business cards, I requested a &#8220;bite&#8221; on the front and a &#8220;kiss&#8221; on the back (putting a deep impression/bite on both sides of your design will show through to the other side).</p>
<h1>2. Create your design accordingly</h1>
<p>Now that you know more about what Letterpress can offer, you can begin developing your design. I used and recommend Illustrator, as it provides crisp designs that are easily translated to this printing technique. A few tips for your design:</p>
<ol>
<li><strong>Sketch it out first.</strong> This is important for any design, but especially a project as costly as Letterpress. You want to ensure you are completely satisfied with your design before investing in this technique.</li>
<li><strong>Keep Letterpress constraints in mind.</strong> Do not use full-color images, extremely small type, or razor thin strokes. Use techniques like halftones and tints with purpose, and keep in mind that they might not always show up as they would with an offset press.</li>
<li><strong>Utilize the benefits of Letterpress</strong>, such as a kiss/bite or by taking advantage of translucent inks to create a third color. You can also get fancy with custom die-cuts (notice the 3-corner die cut on my design below).</li>
<li><strong>Choose your colors wisely.</strong> Color can be a great asset to your design, if utilized properly, and remember to use spot colors, not CMYK.</li>
</ol>
<p>Here is the finalized mock-up of my design:</p>
<p><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/Card-Mockup.jpg"><img class="alignnone size-full wp-image-1285" title="3 Roads Media Business Card Mock-Up" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/Card-Mockup.jpg" alt="" width="600" height="180" /></a></p>
<h1>3. Prepare your design for print</h1>
<p>Printers will ask for your files in whatever best fits their work flow and setup. With that in mind, here are some general file preparation tasks that should make your printer&#8217;s life easier:</p>
<h2>Separate your colors</h2>
<p>Unless you&#8217;re paying a fee to have this done for you, you will need to separate your colors before sending your file to print. <strong>To separate your colors in Adobe Illustrator:</strong></p>
<ol>
<li>First be sure that your artwork is all set. Save this editable art file in case you want to make changes later on.</li>
<li>Once you&#8217;ve saved, choose &#8220;Save As&#8221; and name it something straight forward, like &#8220;Business Card Front.&#8221;</li>
<li>Group your objects together (Object &gt; Group). In my case, I grouped all of the shapes and text.</li>
<li>Outline any live text (Type &gt; Create Outlines) and then expand any stroked objects (Object &gt; Expand).</li>
<li>With your group selected, open your Pathfinder window (Window &gt; Pathfinder) and click the &#8220;Merge&#8221; button under &#8220;Pathfinders.&#8221; This will ensure that nothing is accidentally overlapping.</li>
<li>At this point, all of your colors should be on the same layer, everything grouped and merged into one object.</li>
<li>Use your Direct Selection Tool and select one of your colored objects.</li>
<li>In your top menu bar, click &#8220;Select &gt; Same &gt; Fill Color.&#8221; This will select every object with that same spot color.</li>
<li>Without deselecting this color group, create a new layer (Layers window &gt; Create New Layer).</li>
<li>Move your selection to the new layer &#8211; Edit &gt; Cut &gt; Select your new layer in the layers palette &gt; Edit &gt; <strong>Paste in Front</strong> (you must choose &#8220;Paste in Front&#8221; to keep everything aligned).</li>
<li>Once your selection is on your new layer, regroup it (Object &gt; Group). This layer should now have every object from the one selected spot color.</li>
<li>Repeat this process for remaining spot colors.</li>
<li>Once every color is on its own separate layer, save the file. <em>If you have a double-sided design, save each side as its own separate file.</em></li>
</ol>
<p>In the example below, the gold objects are on layer one, the red &#8220;web&#8221; bubble is on layer 2, and the deep red &#8220;creative strategy&#8221; bubble in on layer 3:</p>
<p><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/3roads-cards-600x400_grid.jpg"><img class="alignnone size-full wp-image-1265" title="3roads cards 600x400_grid" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/3roads-cards-600x400_grid.jpg" alt="" width="600" height="400" /></a></p>
<h2>Pull your bleeds</h2>
<p>If you want your design to go right to the edge, you will need it to &#8220;bleed.&#8221; This simply means expanding the color/imagery past the trim mark. A good rule of thumb is to expand your bleeds at least <strong>1/8&#8243;</strong> past your trim marks. For example, if your finished business card is going to be 3.5&#8243; x 2&#8243;, your design should be at least 3.75&#8243; x 2.25&#8243; with bleeds included. <em>Note: You should get specifics from your printer before finalizing your file, to ensure your file meets their specifications.</em></p>
<h2>Utilize your given space</h2>
<p>When printing mass quantities, it is usually cost effective to print more than one design at a time. In my case, I placed my business card design 4 times on the same file, to decrease press runs and therefore, decrease cost. <strong>By printing 4 cards at once, space, time and resources are used efficiently.</strong> Here is the design after the first color was pressed (notice how different this printed gold color is compared to my original on-screen mock-ups):</p>
<p><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/3roads-cards-600x400_1color.jpg"><img class="alignnone size-full wp-image-1262" title="3roads cards 600x400_1color" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/3roads-cards-600x400_1color.jpg" alt="" width="600" height="400" /></a></p>
<h1>4. Double check, then send to print</h1>
<p>Once you&#8217;ve finished your design, separated your colors, checked your bleeds and margins, and specified any final details like foil stamping or die-cuts, then you are ready to roll. Save your files in an acceptable format, send them off and wait to see how your freshly Letterpressed design comes out! <em>Most printers will also bring you in to do press checks, but if not,  always request press checks for Letterpress, to ensure that what&#8217;s being printed is exactly how you want it before the entire order goes through.</em></p>
<h1><span style="font-weight: normal;">Our newly printed examples</span></h1>
<p>Check out some photos of the recently finished <a href="http://www.3roadsmedia.com/">3 Roads Media</a> business cards below. Special thanks to Denver&#8217;s own <a href="http://www.vintagepressworks.com/">Foils + Dies</a> for the beautiful finished products.</p>
<p><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/3roads-cards-600x400_layout.jpg"><img class="alignnone size-full wp-image-1266" title="3roads cards 600x400_layout" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/3roads-cards-600x400_layout.jpg" alt="" width="600" height="400" /></a></p>
<p>Design details:</p>
<ul>
<li>Created using Adobe Illustrator CS5</li>
<li>3-color wrap-around design</li>
<li>3-corner die cut</li>
<li>Deep &#8220;bite&#8221; for front design/light &#8220;kiss&#8221; for back design</li>
<li>Font: Rockwell</li>
</ul>
<p><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/3roads-cards-600x400_zoom.jpg"><img class="alignnone size-full wp-image-1271" title="3roads cards 600x400_zoom" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/08/3roads-cards-600x400_zoom.jpg" alt="" width="600" height="400" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3roadsmedia.com/blog/how-to-design-for-letterpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multilevel dropdown category navigation in ExpressionEngine</title>
		<link>http://www.3roadsmedia.com/blog/multilevel-dropdown-category-navigation-in-expressionengine/</link>
		<comments>http://www.3roadsmedia.com/blog/multilevel-dropdown-category-navigation-in-expressionengine/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 21:54:50 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[ExpressionEngine]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.3roadsmedia.com/blog/?p=1099</guid>
		<description><![CDATA[If you&#8217;ve ever wanted to create dropdown, category-based navigation in your ExpressionEngine website, you&#8217;ve probably also wanted to punch a hole in your desk. It&#8217;s not easy. Or is it? In this tutorial, I&#8217;ll show you how. Requirements To follow along in this tutorial, you&#8217;ll need: An ExpressionEngine website running EE 1.6.x (I haven&#8217;t yet [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever wanted to create dropdown, category-based navigation in your ExpressionEngine website, you&#8217;ve probably also wanted to punch a hole in your desk. It&#8217;s not easy. Or is it? In this tutorial, I&#8217;ll show you how.<br />
<span id="more-1099"></span></p>
<h2>Requirements</h2>
<p>To follow along in this tutorial, you&#8217;ll need:</p>
<ul>
<li>An ExpressionEngine website running EE 1.6.x (I haven&#8217;t yet tested this in EE 2.0)</li>
<li>The Subcategories plugin</li>
<li>To use category URL titles in your links, <strong>not </strong>category IDs</li>
</ul>
<p>The Subcategories plugin is available for download on <a href="http://expressionengine.com/forums/viewthread/27220/">this thread</a> in the EE forums; however, since it&#8217;s not clear which version to grab, and since there was a minor bug in the code, I&#8217;ve made a corrected version available for direct download <a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/07/pi.subcategories.txt">right here</a>.</p>
<p>Grab the plugin, save it as <strong>pi.subcategories.php</strong>, and upload it to your <strong>system/plugins </strong>directory.</p>
<h2>Live Demo</h2>
<p>If you&#8217;re the visual type (like I am) you probably need to <a href="http://www.3roadsmedia.com/sandbox/index.php/site/">see the menus in action</a>. The demo is pulling from a live EE install on our web server. It may also help to <a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/07/ee_cat_structure.png">see a screenshot of the category heirarchy</a>.</p>
<h2>Template Structure</h2>
<p>Once you&#8217;ve uploaded the plugin file, you&#8217;ll need to create a few templates:</p>
<ol>
<li>embeds/navigation</li>
<li>embeds/subcategories</li>
<li>embeds/sub_subcategories</li>
<li>an additional embed for each additional level of subcategories (if you desire more)</li>
</ol>
<p>For the visuals, here is <a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2010/07/ee_template_page.png">a screenshot of my templates page</a>.</p>
<p>The <strong>embeds/navigation </strong>template controls your main, top-level navigation. Embedding this template as I have done is optional; you can also leave your main navigation code in your header template (or wherever it normally appears).</p>
<p>The <strong>embeds/subcategories </strong>template is only called if a top-level category has any subcategories. It displays a list of, well&#8230;subcategories.</p>
<p>The <strong>embeds/sub_subcategories </strong>template is only called if a subcategory has any subcategories.</p>
<p>You can create as many levels of dropdowns/flyouts as you want by replicating the <strong>embeds/subcategories </strong>template and naming it something else (like embeds/sub_sub_subcategories).</p>
<h2>The Code</h2>
<p>In your <strong>embeds/navigation </strong>template, place the following code:</p>
<pre>&lt;ul id="nav"&gt;
   {exp:weblog:categories parent_only="yes" style="linear"}
      &lt;li&gt;
         {exp:query sql="SELECT cat_id FROM exp_categories WHERE parent_id = '{category_id}' LIMIT 1"}
            &lt;a href="{path='SITE_INDEX'}"{if '{total_results}' &gt; 0} class="fly"{/if}&gt;{category_name}&lt;/a&gt;
            {if '{total_results}' &gt; 0}{embed="embeds/subcategories" cat_id="{category_id}"}{/if}
         {/exp:query}
      &lt;/li&gt;
   {/exp:weblog:categories}
&lt;/ul&gt;</pre>
<p>If you&#8217;re scratching your head about what that all means, here it is:</p>
<ul>
<li>First, we use the <a href="http://expressionengine.com/docs/modules/weblog/categories.html">exp:weblog:categories</a> tag pair to show a list of all categories. We show only top-level categories by using the <strong>parent_only=&#8221;yes&#8221; </strong>parameter.</li>
<li>Next, we output a link to the category and display the name (using <strong>{path=&#8217;SITE_INDEX&#8217;} </strong>removes the &#8220;category&#8221; segment from the URL). The {exp:query} call allows us to add a class of &#8220;fly&#8221; to anchors that are associated with parent categories. This is useful if you&#8217;d like to add styling to your parent categories (<a href="http://www.3roadsmedia.com/sandbox/index.php/site/">see the demo</a> for an example).</li>
<li>The {exp:query} call also checks to see if your top-level categories have children. If so, call the <strong>embeds/subcategories </strong>template.</li>
</ul>
<p>In your <strong>embeds/subcategories </strong>template, place the following code:</p>
<pre>&lt;ul&gt;
   {exp:subcategories root_node="{embed:cat_id}"}
      &lt;li&gt;
         &lt;a href="{homepage}/category/{category_url}"{if '{subcategories_count}' &gt; 0} class="fly"{/if}&gt;{category_name}&lt;/a&gt;
         {if '{subcategories_count}' &gt; 0}{embed="embeds/sub_subcategories" subcat_id="{category_id}"}{/if}
      &lt;/li&gt;
   {/exp:subcategories}
&lt;/ul&gt;</pre>
<p>Here is an explanation of the code:</p>
<ul>
<li>We passed in the parent&#8217;s category ID as <strong>cat_id</strong>. The subcategories plugin takes this value in the <strong>root_node </strong>parameter to pull a list of subcategories.</li>
<li>For each subcategory, output a link. The Subcategories plugin has a neat variable called {subcategories_count}, which lets us replace the SQL query that you see in the embeds/navigation template. If there are subcategories, apply a class of &#8220;fly&#8221; to the anchor. This lets us style our anchors to indicate that there are more dropdowns/flyouts.</li>
<li>Lastly, use the {subcategories_count} variable to see if the current subcategory has subcategories of its own. If so, call the <strong>sub_subcategories </strong>template.</li>
</ul>
<p>In your<strong> embeds/sub_subcategories</strong> template, place the following code:</p>
<pre>&lt;ul&gt;
   {exp:subcategories root_node="{embed:subcat_id}"}
      &lt;li&gt;
         &lt;a href="{homepage}/category/{category_url}"&gt;{category_name}&lt;/a&gt;
      &lt;/li&gt;
   {/exp:subcategories}
&lt;/ul&gt;</pre>
<p>Note how similar this code is to the embeds/subcategories code. The only difference is that we did not check to see if the grandchild categories had subcategories of their own. We can easily do this by adding the following line&#8230;</p>
<pre>{if '{subcategories_count}' &gt; 0}{embed="embeds/sub_sub_subcategories" subcat_id="{category_id}"}{/if}</pre>
<p>&#8230;and then creating an <strong>embeds/sub_sub_subcategories</strong> template. In this way, you can create as many levels of menus as you want.</p>
<h2>Enjoy</h2>
<p>Adding category based dropdown menus to an ExpressionEngine website doesn&#8217;t have to be a drag. This tutorial should get you up and running without trouble; however, if you find bugs or see ways to improve the examples here, let us know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3roadsmedia.com/blog/multilevel-dropdown-category-navigation-in-expressionengine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install and configure sIFR</title>
		<link>http://www.3roadsmedia.com/blog/how-to-install-and-configure-sifr/</link>
		<comments>http://www.3roadsmedia.com/blog/how-to-install-and-configure-sifr/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 00:05:41 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Developer's Toolbox]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.3roadsmedia.com/blog/?p=955</guid>
		<description><![CDATA[0]]></description>
			<content:encoded><![CDATA[<p>Using sIFR (scalable Inman Flash Replacement) to replace standard web fonts on our web projects has become a de facto standard for us. Since I use it so often, I wrote a quick tutorial to show you how to get sIFR up and running.</p>
<p><span id="more-955"></span>This tutorial is geared toward both the novice user installing sIFR for the first time and to those who have done it many times before. If this is your first time working with sIFR, you should know a few things before getting started:</p>
<ul>
<li>To work with sIFR and follow along here, you&#8217;ll need Adobe Flash.</li>
<li>sIFR requires both JavaScript and Flash to work. In the absence of either, it will fall back to displaying regular text.</li>
<li>Don&#8217;t try testing sIFR locally, or nothing will work. It needs to run on a server, either remotely or on a local XAMPP install.</li>
<li>sIFR is not intended to replace large blocks of text. Try to use it sparingly, for headers and small snippets of copy only. Too much sIFR will bog down your site, increasing page load times.</li>
</ul>
<h2>1. Accommodate those without JavaScript</h2>
<p>The very first thing you should do is to make sure your to-be-replaced text looks correct <em>before using sIFR to replace it</em>. If you don&#8217;t do this now, you&#8217;ll spend more time later switching between your sIFR text and your regular text (they end up using different stylesheets) to make sure they both look right. It&#8217;s better to take care of the non-JavaScript people first.</p>
<p>When you&#8217;ve gotten your text where you want it, move on to step #2.</p>
<h2>2. Download the sIFR files</h2>
<p><a href="http://dev.novemberborn.net/sifr3/nightlies/">Download the latest version of sIFR</a> and unzip it somewhere on your computer. For this tutorial, we&#8217;ll be working with sIFR release 436.</p>
<h2>3. Open sifr.fla</h2>
<p>When you unzip the sIFR archive, you&#8217;ll see four folders: css, demo, flash, and js. You can completely ignore the <em>demo </em>folder. Click into the flash folder and open <strong>sifr.fla</strong>.</p>
<h2>4. Modify sifr.fla</h2>
<p>Once you&#8217;ve opened sifr.fla, you should see something like this:</p>
<p style="text-align: center;"><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_empty-stage.png"><img class="aligncenter size-medium wp-image-960" title="Click to enlarge" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_empty-stage-300x195.png" alt="sifr_empty-stage" width="300" height="195" /></a></p>
<p>The white rectangle in the middle is called the <em>stage </em>or the <em>canvas. </em><strong>Double click it </strong>and you&#8217;ll see this:</p>
<p style="text-align: center;"><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_active-stage.png"><img class="aligncenter size-medium wp-image-961" title="Click to enlarge" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_active-stage-300x195.png" alt="sifr_active-stage" width="300" height="195" /></a></p>
<p>Double click the stage again to select the text inside. Delete everything, then <strong>type a single character (glpyh) of your choice for each font style you&#8217;d like. </strong>For instance, if you only need normal and bold styles, enter two glyphs: one for normal and one for bold<strong>. Make sure all of your glyphs are the same letter.</strong><strong><br />
</strong></p>
<p style="text-align: center;"><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_glyphs-on-stage.png"><img class="aligncenter size-medium wp-image-963" title="Click to enlarge" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_glyphs-on-stage-300x195.png" alt="Click to enlarge" width="300" height="195" /></a></p>
<p>Of course, you&#8217;ll have to choose a font that supports all of the styles you need. <strong>In this tutorial, I&#8217;m using Arno Pro</strong>, which has bold, italic, and bold italic glyphs.</p>
<h2>5. Choose your font</h2>
<p>Select all of your glyphs, then look to the right of your screen for a dropdown menu like the one highlighted below:</p>
<p style="text-align: center;"><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_choose-font.png"><img class="aligncenter size-medium wp-image-964" title="Click to enlarge" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_choose-font-300x195.png" alt="Click to enlarge" width="300" height="195" /></a></p>
<p>All of your characters will now be the default &#8220;normal&#8221; style of the chosen font. If your font supports additional styles, the &#8220;Style&#8221; menu will be active. Highlight each individual glyph you want to change, then choose a different style from the dropdown. In the example below, I&#8217;m about to make the second glyph italic:</p>
<p style="text-align: center;"><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_choose-italic.png"><img class="aligncenter size-medium wp-image-965" title="Click to enlarge" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_choose-italic-300x195.png" alt="Click to enlarge" width="300" height="195" /></a></p>
<p>For fonts like Arno Pro, which have tons of glyph styles, you may be tempted to pick a &#8220;caption&#8221; or &#8220;extra wide&#8221; style. <strong>These will not work, </strong>since HTML only supports normal, bold, italic, and bold italic.</p>
<blockquote><p>TIP: If you only need to display one style on your site, then you only need one glyph on your stage. I.e., if you only want to display bold, then type one glyph and bold it. You don&#8217;t need any more than that.</p></blockquote>
<h2>6. Add additional glyphs</h2>
<p>If you anticipate using special characters (for example, Ñ, β, £, «, ™), you&#8217;ll need to embed them in your Flash movie. Right beneath the menus you just worked with is a &#8220;Character Embedding&#8221; button which, when clicked, pops up a window like this:</p>
<p style="text-align: center;"><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_embed-chars.png"><img class="aligncenter size-medium wp-image-966" title="Click to enlarge" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_embed-chars-300x195.png" alt="Click to enlarge" width="300" height="195" /></a></p>
<p>The basic glyph sets are already chosen for you, along with a list of extra characters. Choose the additional character sets you want (if any) or type special characters in the list, then click OK.</p>
<h2>7. Publish your movie</h2>
<p>When you&#8217;re happy with your font, go to <strong>File › Publish Settings.</strong> Untick the box near &#8220;HTML&#8221; since we won&#8217;t need to output any HTML files. Next, click the &#8220;Flash&#8221; tab near the top to adjust your settings.</p>
<p>The only setting you should change is <strong>JPEG quality. </strong>I always set it to 100, since there&#8217;s almost never a difference in file size between 80 and 100. This ensures your replaced text looks as good as possible. You can, of course, adjust this setting to try and reduce the size of your Flash movie.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-967" title="Publish settings for the sIFR Flash movie" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_set-jpeg.png" alt="Click to enlarge" width="456" height="676" /></p>
<p>Once this is set, click <strong>Publish</strong>.</p>
<h2>8. Rename your movie</h2>
<p>Go back to the folder that has your sIFR files and click into the &#8220;flash&#8221; folder. You should now see a <strong>sifr.swf</strong> file, which is the movie you just published.</p>
<p>It&#8217;s good practice to rename your movie after the font it contains, since it&#8217;s not uncommon to replace more than one font on a website. This naming convention will make it easy to know what&#8217;s what.</p>
<p>I renamed my movie <strong>arnopro.swf</strong>.</p>
<h2>9. Open sifr-config.js and configure</h2>
<p>Now it&#8217;s time for the hearty, meat-and-potatoes part of the tutorial. You&#8217;ve got your movie; you just need to tell your site where to find it and what to do with it.</p>
<p>Go to your sIFR folder, click into the &#8220;js&#8221; folder, and open <strong>sifr-config.js</strong>.</p>
<p>There are instructions in the file, but here are the basics:</p>
<ul>
<li>On line 15, change the variable name to match your font&#8217;s name and change the path to point to your swf file. For example:</li>
</ul>
<pre><span style="color: #888888;">// what you see when you open the file</span>
<span style="color: #000080;">var</span> futura <span style="color: #000080;">= {</span> src<span style="color: #0000ff;">: '/path/to/futura.swf'</span> <span style="color: #000080;">}</span>;
<span style="color: #888888;">
// an example of what you should change it to</span>
<span style="color: #000080;">var</span> arnopro <span style="color: #000080;">= {</span> src<span style="color: #0000ff;">: 'http://www.3roadsmedia.com/flashstuff/arnopro.swf'</span> <span style="color: #000080;">}</span>;</pre>
<ul>
<li>Now is a good time to upload everything to a web server so you know the path to your movie. <strong>You won&#8217;t be able to test sIFR by just calling the movie from your hard drive.</strong></li>
<li>Do a find/replace to swap out all instances of <strong>futura </strong>with the name of your new font.</li>
<li>Tell sIFR how to display your new font by adding CSS selectors and style rules (see the next step)</li>
</ul>
<h2>10. Tell sIFR how to display your new font</h2>
<p>All of the styling for your Flash-based font is handled via <strong>sifr-config.js</strong>, starting on line 53.</p>
<p>A couple of pointers:</p>
<ul>
<li>Be sure the font name after <strong>sIFR.replace</strong> matches the name you specified in line 15</li>
<li>The &#8220;selector:&#8221; tells sIFR which HTML element to target with the style rules. sIFR supports <a href="http://wiki.novemberborn.net/sifr3/Selectors">most HTML elements</a>, but if you want to target things like :first-child, <a href="http://wiki.novemberborn.net/sifr3/parseSelector">read this article</a> on how to do it.</li>
<li>You can target multiple selectors at a time by using a comma-separated list; e.g.:</li>
</ul>
<pre>selector<span style="color: #0000ff;">: 'h1, h2 a, #footer h3'</span>,</pre>
<ul>
<li>When using hex colors, <strong>always use the full six digits. </strong>Three-digit CSS shortcuts do <em>not </em>work here. For instance, use #003300, <em>not </em>#030.</li>
<li>If you&#8217;re getting a funky colored box behind your replaced text, add this line to each of your selectors:</li>
</ul>
<pre>wmode<span style="color: #0000ff;">: 'transparent'</span></pre>
<ul>
<li>To style hyperlink <strong>hover </strong>behavior, do something like the following:</li>
</ul>
<pre>css<span style="color: #0000ff;">: [
   '.sIFR-root { color: #000000; }',
   'a { color:#9f2321; text-decoration:none; }',
   'a:hover { color:#99e232; text-decoration:underline; }'
   ]</span></pre>
<h2>11. Include the sIFR files in your web page</h2>
<p>For this tutorial, I&#8217;m assuming you already know how you want to style your font, so you can configure first and hook up second (sounds like I&#8217;m inviting some derisive snickering&#8230;).</p>
<p>sIFR requires 3 files to work: sifr.css, sifr.js, and sifr-config.js.</p>
<p>Add these files to the &lt;head&gt; section of your web pages by copying/pasting this:</p>
<pre><span style="color: #808080;">&lt;!-- sIFR files --&gt;</span>
<span style="color: #000080;">&lt;link rel=</span><span style="color: #0000ff;">"stylesheet"</span> <span style="color: #000080;">type=</span><span style="color: #0000ff;">"text/css"</span> <span style="color: #000080;">href=</span><span style="color: #0000ff;">"http://path/to/sifr.css"</span> <span style="color: #000080;">/&gt;</span>
<span style="color: #800000;">&lt;script type=</span><span style="color: #0000ff;">"text/javascript"</span> <span style="color: #800000;">src=</span><span style="color: #0000ff;">"http://path/to/sifr.js"</span><span style="color: #800000;">&gt;&lt;/script&gt;</span>
<span style="color: #800000;">&lt;script type=</span><span style="color: #0000ff;">"text/javascript"</span> <span style="color: #800000;">src=</span><span style="color: #0000ff;">"http://path/to/sifr-config.js"</span><span style="color: #800000;">&gt;&lt;/script&gt;</span></pre>
<h2>12. Upload everything and test</h2>
<p>Upload everything to your web server and load your web page. If all went as planned, you should see your new font instead of that old, dreary thing you&#8217;re replacing:</p>
<p style="text-align: center;"><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_font-final.png"><img class="aligncenter size-full wp-image-968" title="A before and after shot. Much better." src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/10/sifr_font-final.png" alt="A before and after shot. Much better." width="452" height="222" /></a></p>
<p>If you <em>don&#8217;t </em>see your new font, go through this checklist:</p>
<ul>
<li>Double check the paths to all of your files.</li>
<li>If your JS files are linked properly, make sure you entered the right path on line 15 of sifr-config.js.</li>
<li>If <em>that&#8217;s </em>linked properly, try to load the Flash movie directly. If you don&#8217;t get anything, you may not have Flash installed or it may be turned off.</li>
<li>Make sure JavaScript is enabled in your browser.</li>
</ul>
<p>Once you&#8217;ve got your replaced font showing, tweak your CSS in sifr-config.js until things are exactly where you want them.</p>
<h2>13. Tweak the CSS</h2>
<p>The final step is to tweak your replaced text. You may notice it&#8217;s a bit off in some places, or that it wraps in the middle of a word. The solution is to edit <strong>sifr.css</strong>, which is located in the &#8220;css&#8221; folder of your sIFR download.</p>
<p>Once you&#8217;ve opened that file, scroll to the very bottom, where you&#8217;ll see this:</p>
<pre><span style="color: #800000;">@media screen {</span>
<span style="color: #808080;"> /* Example:
 .sIFR-active h1 {
 font-family: Verdana;
 visibility: hidden;
 }
 */</span>
<span style="color: #800000;">}</span></pre>
<p>This is where you make your edits (you can leave the rest of the file alone).</p>
<p>A common fix you may need to implement is <strong>preventing your replaced text from wrapping in the middle of a word</strong>. This is caused by the replaced text taking up less space than the sIFR text. The solution is to increase the font size, letter-spacing, or width of the replaced text. If you do this in your <em>regular </em>CSS file, you may find that your regular (non-sIFR) text is too large.</p>
<p>In this case, you&#8217;d create a new rule in your sifr.css file to make the font larger <em>only for the replaced text</em>; e.g.:<em><br />
</em></p>
<pre><span style="color: #888888;">// regular CSS file</span>
<span style="color: #ff00ff;">h1 {</span> <span style="color: #0000ff;">font-size</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">20px</span><span style="color: #ff00ff;">; }</span>

<span style="color: #888888;">// sifr.css</span>
<span style="color: #ff00ff;">.sIFR-active h1 {</span> <span style="color: #0000ff;">font-size</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">28px</span><span style="color: #ff00ff;">;</span> <span style="color: #0000ff;">visibility</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">hidden</span><span style="color: #ff00ff;">; }</span><span style="color: #ff00ff;"> </span></pre>
<p>Regardless of whether you edit sifr.css, you must include it in your &lt;head&gt; section.</p>
<h2>Post script: frequently asked questions</h2>
<p>You&#8217;ve got sIFR up and running, but something isn&#8217;t acting quite right? I&#8217;ve compiled this short list of questions that I&#8217;ve seen asked many times before:</p>
<h3>How do I adjust line-height in sIFR?</h3>
<p>Flash doesn&#8217;t understand the concept of line-height. Instead, it uses a custom property called <strong>leading. </strong>To adjust the line-height in sIFR, do this in your sifr-config file:</p>
<pre>// leading must be a number (decimals allowed); no units needed
css<span style="color: #0000ff;">: '.sIFR-root { color:#5a3b00; font-size:25px; <strong>leading: -3;</strong> }'</span>,</pre>
<h3>How do I style links in sIFR? My cursor doesn&#8217;t work.</h3>
<p>A common problem with sIFR-replaced links is that your cursor doesn&#8217;t appear as the friendly hand pointer, but as a text selector. This is because you haven&#8217;t replaced the link, but the text <em>inside </em>the link. <a href="http://wiki.novemberborn.net/sifr/FAQ#replacing-links">Read here</a> for how to fix this.</p>
<h2>That&#8217;s it!</h2>
<p>If you have suggestions for improving this tutorial, or if you get stuck, feel free to leave a comment. You can also post a question at <a href="http://stackoverflow.com/">Stack Overflow</a> where Mark Wubben (lead sIFR developer) is great at answering questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3roadsmedia.com/blog/how-to-install-and-configure-sifr/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Improving WordPress page navigation: fixing next_post_link() and previous_post_link()</title>
		<link>http://www.3roadsmedia.com/blog/improving-wordpress-page-navigation/</link>
		<comments>http://www.3roadsmedia.com/blog/improving-wordpress-page-navigation/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 18:06:07 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Developer's Toolbox]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.3roadsmedia.com/?p=746</guid>
		<description><![CDATA[0]]></description>
			<content:encoded><![CDATA[<p>WordPress&#8217; next_post_link() and previous_post_link() functions are used to navigate between posts in single post (permalink) view. They work great&#8230;until you come to the very first or the very last post.</p>
<p><span id="more-746"></span>When viewing the latest post, <strong>next_post_link() </strong>displays nothing; when viewing the earliest post, <strong>previous_post_link() </strong>displays nothing. This can result in some less than friendly navigation.</p>
<p><strong>In this post, </strong><strong>I&#8217;ll show you how to use a built-in WordPress function and PHP conditionals to improve your WordPress page navigation.</strong></p>
<h2>The problem</h2>
<p>Here is an example of <strong>next_post_link() </strong>and <strong>previous_post_link() </strong>at work on our blog&#8217;s old theme:</p>
<div id="attachment_756" class="wp-caption aligncenter" style="width: 526px"><img class="size-full wp-image-756" title="wp_post_functions_example" src="http://www.3roadsmedia.com/blog/wp-content/uploads//2009/09/wp_post_functions_example.png" alt="wp_post_functions_example" width="516" height="128" /><p class="wp-caption-text">When viewing a post that is neither the newest nor the oldest, the post navigation links display as expected.</p></div>
<p>The trouble with these functions comes when you get to the first or last post. In the case of the first, you&#8217;ll have something like this:</p>
<div id="attachment_757" class="wp-caption aligncenter" style="width: 526px"><img class="size-full wp-image-757" title="wp_post_functions_missing_previous" src="http://www.3roadsmedia.com/blog/wp-content/uploads//2009/09/wp_post_functions_missing_previous.png" alt="wp_post_functions_missing_previous" width="516" height="128" /><p class="wp-caption-text">When viewing the oldest post, the &quot;previous post&quot; link disappears, leaving an ugly hole.</p></div>
<p>And when viewing the last post, you&#8217;ll have something like this:</p>
<div id="attachment_758" class="wp-caption aligncenter" style="width: 526px"><img class="size-full wp-image-758" title="wp_post_functions_missing_next" src="http://www.3roadsmedia.com/blog/wp-content/uploads//2009/09/wp_post_functions_missing_next.png" alt="wp_post_functions_missing_next" width="516" height="128" /><p class="wp-caption-text">Similarly, when viewing the newest post, the &quot;next post&quot; link disappears.</p></div>
<h2>To the rescue: get_adjacent_post</h2>
<p>We&#8217;re going to use the obscure WordPress function <strong>get_adjacent_post()</strong> to check if&#8230; (shockingly) &#8230;there is an adjacent post. If there isn&#8217;t, we output whatever HTML markup we like to take the place of the gaping hole we&#8217;re trying to fill. If there <em>is </em>an adjacent post, we output it as normal.</p>
<p>The function retrieves a link to the adjacent post (either next or previous) and takes the following form&#8230;</p>
<pre>get_adjacent_post([bool $in_same_cat, string $excluded_categories, bool $previous])</pre>
<p>&#8230;and has these parameters:</p>
<ul>
<li><strong>$in_same_cat</strong> : Whether the link should be in the same category</li>
<li><strong>$excluded_categories</strong> : A comma-separated list of excluded category IDs</li>
<li><strong>$previous</strong> : Whether to retrieve the previous post</li>
</ul>
<h2>The solution, with sample markup</h2>
<p>The code block below contains the markup you should add to your <strong>single.php</strong> template file. Place it where you&#8217;d like your navigation to appear, then adjust the parameters and output to suit your needs.</p>
<pre><span style="color: #000080;">&lt;span id=<span style="color: #0000ff;">"prev"</span>&gt;</span>
   <span style="color: #ff0000;">&lt;?php</span> previous_post_link<span style="color: #000080;">(</span><span style="color: #ff0000;">'%link'</span>, <span style="color: #ff0000;">'&amp;laquo; Previous'</span><span style="color: #000080;">)</span>; <span style="color: #ff0000;">?&gt;</span>
   <span style="color: #ff0000;">&lt;?php</span> <span style="color: #008000;">if</span><span style="color: #000080;">(!</span>get_adjacent_post<span style="color: #000080;">(</span><span style="color: #008000;">false</span>, <span style="color: #ff0000;">''</span>, <span style="color: #008000;">true</span><span style="color: #000080;">))</span> <span style="color: #000080;">{</span> <span style="color: #0000ff;">echo </span><span style="color: #ff0000;">'&lt;span&gt;&amp;laquo;Previous&lt;/span&gt;'</span>; <span style="color: #000080;">}</span> <span style="color: #ff9900;">// if there are no older articles</span> <span style="color: #ff0000;">?&gt;</span>
<span style="color: #000080;">&lt;/span&gt;</span>
<span style="color: #000080;">&lt;span id=<span style="color: #0000ff;">"next"</span>&gt;</span>
   <span style="color: #ff0000;">&lt;?php</span> next_post_link<span style="color: #000080;">(</span><span style="color: #ff0000;">'%link'</span>, <span style="color: #ff0000;">'Next &amp;raquo;'</span><span style="color: #000080;">)</span>; <span style="color: #ff0000;">?&gt;</span>
   <span style="color: #ff0000;">&lt;?php</span> <span style="color: #008000;">if</span><span style="color: #000080;">(!</span>get_adjacent_post<span style="color: #000080;">(</span><span style="color: #008000;">false</span>, <span style="color: #ff0000;">''</span>, <span style="color: #008000;">false</span><span style="color: #000080;">))</span> <span style="color: #000080;">{</span> <span style="color: #0000ff;">echo </span><span style="color: #ff0000;">'&lt;span&gt;Next &amp;raquo;&lt;/span&gt;'</span>; <span style="color: #000080;">}</span> <span style="color: #ff9900;">// if there are no newer articles</span> <span style="color: #ff0000;">?&gt;</span>
<span style="color: #000080;">&lt;/span&gt;</span></pre>
<p>I then added this line to my CSS file:</p>
<pre><span style="color: #ff00ff;">#prev span, #next span { <span style="color: #000080;">color</span>:<span style="color: #0000ff;">#ccc</span>; }</span> <span style="color: #999999;">/* lighter than the normal anchor text */</span></pre>
<p>And here is the final result:</p>
<div id="attachment_759" class="wp-caption aligncenter" style="width: 526px"><img class="size-full wp-image-759" title="wp_post_functions_result" src="http://www.3roadsmedia.com/blog/wp-content/uploads//2009/09/wp_post_functions_result.png" alt="wp_post_functions_result" width="516" height="256" /><p class="wp-caption-text">The final result, showing user-friendly language at both ends.</p></div>
<p>In the example above, I grayed out the inactive links. If you have more room, you might get creative by replacing the text with something like &#8220;Sorry, there aren&#8217;t any newer posts!&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3roadsmedia.com/blog/improving-wordpress-page-navigation/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Use a ModalBox to edit content inline with ExpressionEngine</title>
		<link>http://www.3roadsmedia.com/blog/use-a-modal-box-to-edit-content-inline-with-expressionengine/</link>
		<comments>http://www.3roadsmedia.com/blog/use-a-modal-box-to-edit-content-inline-with-expressionengine/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 20:59:20 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Developer's Toolbox]]></category>
		<category><![CDATA[ExpressionEngine]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.3roadsmedia.com/?p=437</guid>
		<description><![CDATA[0]]></description>
			<content:encoded><![CDATA[<p>A couple months ago, I wrote a post on <a href="http://www.3roadsmedia.com/blog/inline-editing-with-expressionengine-and-ajax/">how to use AJAX to edit content inline</a> &#8211; without accessing the control panel and without a page refresh.</p>
<p>Since then, I&#8217;ve found a much cooler and more practical way of editing content inline: by using a <a href="http://en.wikipedia.org/wiki/Modal_window">modal box</a>. The result is the same: authorized users can update certain content blocks without control panel access and without any knowledge of HTML.</p>
<p><span id="more-437"></span>In fact, I think this method is far more robust, flexible, and user friendly than the AJAX one I shared with you a while back.</p>
<p>Let&#8217;s get started.</p>
<h2>What is a modal box?</h2>
<p>If you already know what a modal box is and why you would use it with ExpressionEngine, feel free to <a href="#step1">skip ahead</a> to the implementation.</p>
<p>A modal box is a JavaScript driven dialogue box that &#8220;pops over&#8221; a page&#8217;s content. It is not a separate popup window, so it won&#8217;t be blocked by a user&#8217;s browser. Perhaps most importantly, a modal box requires the user to interact with it before the user can do anything else on the page.</p>
<div id="attachment_440" class="wp-caption aligncenter" style="width: 500px"><img class="size-full wp-image-440" title="modal-box-example" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/05/modal-box-example.jpg" alt="A simple modal box" width="490" height="353" /><p class="wp-caption-text">A simple modal box</p></div>
<h2>Why use a modal box for inline editing?</h2>
<p>Usability. A modal box does not require the user to leave the current page, which means a user can interact with the dialogue (or series of dialogues) while still seeing the same page in the background.</p>
<p>For ExpressionEngine users in particular, <strong>not having to leave the page you want to edit is a big bonus</strong>, since finding a particular weblog entry in the control panel can be time consuming.</p>
<h2>Can I see a demonstration?</h2>
<p><a href="http://www.3roadsmedia.com/sandbox/index.php/modalbox_test/index/">Here is the end result</a> of this tutorial. Feel free to make some changes &#8211; these are posting to an actual EE database so you can see how this method works.</p>
<p>You can also go to <a href="http://www.wildbit.com/labs/modalbox/">Wildbit&#8217;s Modal Box page</a> and check out the demos.</p>
<h2>Getting a modal box to work with ExpressionEngine</h2>
<p>The goal for this tutorial is to implement a modal box that allows us to edit the content of an ExpressionEngine weblog entry <strong>inline</strong>; that is, without control panel access.</p>
<h3 id="step1">Step 1: Create a new weblog, custom fields, and template group</h3>
<p>To be as comprehensive as possible, I&#8217;ll assume that you&#8217;re starting with a fresh EE install. If you already have weblogs set up, <a href="#step2">skip to the next step</a>.</p>
<p>Create a new weblog (in a flash of brilliance, I named mine &#8220;ModalBox Test&#8221; and gave it a short name of <strong>modalbox_test</strong>).</p>
<p>Create a new custom field group (or use the default one). Make sure it has at least one text input field type and one textarea field type. I set the formatting for my fields to &#8220;none,&#8221; but you don&#8217;t have to.</p>
<div id="attachment_443" class="wp-caption aligncenter" style="width: 500px"><img class="size-full wp-image-443" title="modalbox-ee-custom-fields" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/05/modalbox-ee-custom-fields.png" alt="I created two custom fields for this tutorial. Use the short names above if you plan to follow this tutorial to a T." width="490" height="146" /><p class="wp-caption-text">Use the short names above if you plan to follow this tutorial to a T.</p></div>
<p>Assign your field group to your modalbox_test weblog.</p>
<p>Create a new template group. I called mine <strong>modalbox_test</strong>, the same as the weblog.</p>
<h3 id="step2">Step 2: Grab the ModalBox files</h3>
<p>Visit Wildbit&#8217;s site and <a href="http://www.wildbit.com/labs/modalbox/">download the latest version of ModalBox</a> (I&#8217;m using 1.6.0 for this tutorial).</p>
<p>Extract the zip file on your computer, then upload the <strong>modalbox1.6.0</strong> folder to your web server. For this tutorial, I renamed my modalbox1.6.0 folder to <strong>modalbox </strong>and uploaded it to my <strong>system/scripts </strong>folder (this folder does not exist by default, so you will have to create it).</p>
<div id="attachment_442" class="wp-caption aligncenter" style="width: 500px"><img class="size-full wp-image-442" title="modalbox-folder-location1" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/05/modalbox-folder-location1.png" alt="For the visually inclined." width="490" height="186" /><p class="wp-caption-text">For the visually inclined.</p></div>
<p>The <strong>system </strong>folder is EE&#8217;s default system folder. You may have renamed it to something else.</p>
<h3>Step 3: Link the ModalBox files to your template</h3>
<p>I&#8217;ve prepared the following code block that you can use in your new template. If you&#8217;re using my custom field names from <a href="#step1">Step #1</a>, you don&#8217;t need to change anything. Otherwise, be sure to replace my custom field names with your own.</p>
<p>Copy and paste the following code into your <strong>modalbox_test/index</strong> template (the calls to the ModalBox files are in <span style="color: #ff0000;"><strong>red boldface</strong></span>):</p>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
    &lt;title&gt;Inline Editing with Modal Boxes&lt;/title&gt;
    &lt;link rel="stylesheet" type="text/css" href="{stylesheet=weblog/stylesheet}" /&gt;

    &lt;!-- Modalbox files --&gt;
<span style="color: #ff0000;"><strong>    &lt;script type="text/javascript" src="{scripts}/modalbox/lib/prototype.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="{scripts}/modalbox/lib/scriptaculous.js?load=effects"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="{scripts}/modalbox/modalbox.js"&gt;&lt;/script&gt;
    &lt;link rel="stylesheet" type="text/css" href="{scripts}/modalbox/modalbox.css" media="screen" /&gt;</strong></span>
    &lt;!--// Modalbox files --&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;h1&gt;An example of inline editing with ExpressionEngine and Modal Boxes&lt;/h1&gt;

&lt;ul&gt;
    {exp:weblog:entries disable="categories|member_data|pagination|trackbacks" weblog="modalbox_test"}
        &lt;li&gt;
            &lt;h2&gt;{title}&lt;/h2&gt;
            &lt;p&gt;&lt;strong&gt;{modalbox_input}&lt;/strong&gt;&lt;/p&gt;
            &lt;p&gt;{modalbox_textarea}&lt;/p&gt;
        &lt;/li&gt;
    {/exp:weblog:entries}
&lt;/ul&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>Notice the {scripts} variable. </strong>That is a global variable I set up in EE that contains the path to my scripts folder (e.g., http://www.yoursite.com/system/scripts).</p>
<h3>Step 4. Add an &#8220;Edit&#8221; link</h3>
<p>Before you go any further, add some test entries, then preview your template to make sure everything is hooked up correctly.</p>
<p>Once that&#8217;s done, add the following line of code to your template. Place it where you&#8217;d like the &#8220;Edit&#8221; link to appear (I placed mine right below the &lt;h2&gt; tags in the sample code).</p>
<pre>{if logged_in}&lt;a onclick=<code><span style="color: #000000;"><span style="color: #dd0000;">"Modalbox.show($('modalbox-content-{entry_id}'), {title: this.title, width: 800}); return false;" </span><span style="color: #0000bb;">title</span><span style="color: #007700;">=</span><span style="color: #dd0000;">"Edit this weblog entry" </span><span style="color: #0000bb;">href</span><span style="color: #007700;">=</span><span style="color: #dd0000;">"#"</span><span style="color: #007700;">&gt;</span><span style="color: #0000bb;">Edit</span><span style="color: #007700;">&lt;/</span><span style="color: #0000bb;">a</span><span style="color: #007700;">&gt;{/if}</span></span></code></pre>
<p>This line of code tells the ModalBox script to load a DIV with an ID of <strong>modalbox-content-XX</strong> (where XX is the entry&#8217;s ID) into a ModalBox that is 800 pixels wide with a heading of &#8220;Edit weblog entry.&#8221;</p>
<h3>Step 5. Create the DIV</h3>
<p>In the previous step, we told ModalBox to find and display a DIV with a particular ID. This DIV will contain a SAEF (<a href="http://expressionengine.com/wiki/Hard_Coded_Stand_Alone_EDIT_Form_Guide/">stand alone edit form</a>), which allows us to easily and safely post our changes to the EE database.</p>
<p><a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/06/SAEF.txt">Grab the SAEF code here</a> and paste it wherever you like in your main template, so long as it is within the {exp:weblog:entries} tags.</p>
<p>The only thing you&#8217;ll need to change in the SAEF are the custom field ID numbers associated with each of your custom fields.</p>
<p>What?</p>
<p>When you created custom fields for your weblog, ExpressionEngine assigned each of them a unique ID number. We need to know what these numbers are in order to pull the correct information from the database.</p>
<p><strong>To find these numbers</strong>, go to Admin › Weblog Administration › Custom Weblog Fields, then click &#8220;Add/Edit Custom Fields&#8221; next to the field group you created for this tutorial. Mouse over each of your custom fields and note the number that appears in the bottom left of your browser:</p>
<div id="attachment_444" class="wp-caption aligncenter" style="width: 509px"><img class="size-full wp-image-444" title="modalbox-ee-custom-field-id-explanation" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/05/modalbox-ee-custom-field-id-explanation.png" alt="How to find a field ID for your custom fields" width="499" height="251" /><p class="wp-caption-text">How to find a field ID for each of your custom fields</p></div>
<p>Here are my field IDs:</p>
<ul>
<li>modalbox_input: <strong>73</strong></li>
<li>modalbox_textarea: <strong>74</strong></li>
</ul>
<p>In your SAEF, find any references to these field IDs. <strong>They will look like field_id_XX, where XX is the field ID</strong>. For example, I would change my SAEF to look like this (my changes are in <span style="color: #ff0000;"><strong>red</strong></span>):</p>
<pre>&lt;label for="amount"&gt;Modalbox Input&lt;/label&gt;
&lt;input type="text" name="<strong>field_id_<span style="color: #ff0000;">73</span></strong>" id="amount" value="{modalbox_input}" /&gt;
&lt;input type="hidden" name="<strong>field_ft_<span style="color: #ff0000;">73</span></strong>" value="none" /&gt;

&lt;label for="details"&gt;Modalbox Textarea&lt;/label&gt;
&lt;textarea name="<strong>field_id_<span style="color: #ff0000;">74</span></strong>" id="details"&gt;{modalbox_textarea}&lt;/textarea&gt;
&lt;input type="hidden" name="<strong>field_ft_<span style="color: #ff0000;">74</span></strong>" value="none" /&gt;</pre>
<p><strong>The field_ft_XX lines control the formatting for a particular field</strong>. You can leave them set to &#8220;none&#8221; to remove all HTML formatting.</p>
<h3>Step 6. Test your ModalBox</h3>
<p>Save and preview your template, then click an &#8220;Edit&#8221; link to call the ModalBox. If you&#8217;ve followed along closely, you&#8217;ll see a form populated with your weblog entry&#8217;s content.</p>
<div id="attachment_464" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-464" title="The results of our hard work" src="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/06/modalbox-success.png" alt="The results of our hard work" width="500" height="207" /><p class="wp-caption-text">The results of our hard work</p></div>
<p>Make some changes and click &#8220;Save&#8221; and you should be sent to the location specified in the &#8220;return&#8221; parameter of your SAEF. If this is the same page you just came from, you should see your changes.</p>
<h3>Step 7. Add a success message</h3>
<p>If you make a change and get dumped back on a page without any visual cues that something changed, you (or your client) may not have a clue what just happened.</p>
<p>That&#8217;s why I suggest adding a success message.</p>
<p>First, alter the <strong>return </strong>parameter in your SAEF to include the following:</p>
<pre>return="modalbox_test/index<strong>/?updated=true</strong>"</pre>
<p>You can set &#8220;updated&#8221; to be anything you like; it&#8217;s just a variable name.</p>
<p>Next, in the page you are returning to (modalbox_test/index), add the following lines of PHP:</p>
<pre class="codeblock">&lt;?php
    if(stristr($_SERVER['REQUEST_URI'], 'updated=true')) { $updated = 1; }

    if(isset($updated)) {
        echo "&lt;div&gt;Your weblog entry was successfully updated.&lt;/div&gt;";
    }
?&gt;</pre>
<p>This snippet checks the URL for the segment we just added; if it finds it, then it displays a success message.</p>
<h3>Step 8. Add a dropdown menu</h3>
<p>In my last tutorial on inline editing, I didn&#8217;t touch the subject of dropdowns, since trying to get them to work with that script was impossible.</p>
<p>Luckily, we can use the SAEF with a bit of PHP to get what we need. Add the following where you&#8217;d like your dropdown to appear in the SAEF, being sure to replace the field IDs as needed:</p>
<pre>&lt;label for="dropdown"&gt;Dropdown List&lt;/label&gt;
<span class="punct">&lt;</span><span class="ident">select</span> <span class="ident">name</span><span class="punct">="</span><strong><span class="string">field_id_<span style="color: #ff0000;">XX</span></span></strong><span class="punct">"&gt;
    {</span><span class="ident">exp</span><span class="symbol">:query</span> <span class="ident">sql</span><span class="punct">="</span><span class="string">SELECT field_list_items FROM exp_weblog_fields WHERE field_id = '<span style="color: #ff0000;"><strong>XX</strong></span>' </span><span class="punct">"}</span>
        <span class="punct">&lt;?</span>php
            <span class="global">$items</span> <span class="punct">="</span><span class="string">{field_list_items}</span><span class="punct">";</span>
            <span class="global">$items</span> <span class="punct">=</span> <span class="ident">explode</span><span class="punct">("</span><span class="string"><span class="escape">\n</span></span><span class="punct">",</span> <span class="global">$items</span><span class="punct">);</span>
<span class="global">            $howmany</span> <span class="punct">=</span> <span class="ident">count</span><span class="punct">(</span><span class="global">$items</span><span class="punct">);</span>
            <span class="global">$i</span> <span class="punct">=</span> <span class="number">0</span><span class="punct">;</span> <span class="keyword">do</span> <span class="punct">{</span>
<span class="global">            $item_id</span> <span class="punct">=</span> <span class="global">$items</span><span class="punct">[</span><span class="global">$i</span><span class="punct">];</span>
        <span class="char">?&gt;</span>
        <span class="punct">&lt;</span><span class="ident">option</span> <span class="ident">value</span><span class="punct">="</span><span class="string">&lt;?=$item_id?&gt;</span><span class="punct">"&gt;&lt;</span><span class="char">?=</span><span class="global">$item_id</span><span class="char">?&gt;</span><span class="punct">&lt;/</span><span class="regex">option&gt;
        &lt;?php
            $i++; } while ($i &lt; $howmany);
        ?&gt;
    {</span><span class="punct">/</span><span class="ident">exp</span><span class="symbol">:query</span><span class="punct">}
&lt;/</span><span class="regex">select&gt;</span></pre>
<p>This bit of code will loop through all of your manually entered dropdown items, then display them.</p>
<h3>Step 9. Enjoy!</h3>
<p>Feel free to share your own experiences, or to suggest ways to improve the code I&#8217;ve presented here. Have a question? Got stuck and need help? Let me know!</p>
<h3>Postscript: Streamlining your implementation</h3>
<p>I was fortunate enough to receive some feedback from <a href="http://www.stolpmann.eu/">Markus Stolpmann</a>, a fellow EE user, on how to improve the modalbox implementation. The steps above are fine if you don&#8217;t mind including hidden divs in your code – but what if this isn&#8217;t your cup of tea?</p>
<p>It&#8217;s far easier to maintain your code if you include the SAEF in a separate template.</p>
<p>To begin, create a new template group (something like <strong>modalboxes </strong>works well). This new group will hold all of the content shown in your modal boxes. Our company intranet, for example, has templates like:</p>
<ul>
<li>modalboxes/add_prospect</li>
<li>modalboxes/add_invoice</li>
<li>modalboxes/edit_prospect</li>
<li>modalboxes/edit_invoice</li>
</ul>
<p>Each of these templates contains a SAEF with fields specific to the task (i.e., I won&#8217;t have an &#8220;invoice number&#8221; input box in my <strong>edit_prospect </strong>template). Here is an example of what my <strong>modalboxes/edit_prospect</strong> template looks like:</p>
<pre>{exp:weblog:entry_form weblog="prospects" return="prospects/prospect_added"}
    &lt;ul&gt;
        &lt;li&gt;
            &lt;label for="title"&gt;Prospect Name&lt;em&gt;*&lt;/em&gt;&lt;/label&gt;
            &lt;input type="text" name="title" id="title" value="{title}" maxlength="100" onkeyup="liveUrlTitle();" /&gt;
        &lt;/li&gt;
        &lt;li&gt;
            &lt;label for="email"&gt;Email&lt;/label&gt;
            &lt;input type="text" name="field_id_4" id="email" /&gt;
        &lt;/li&gt;
        ...
        &lt;li&gt;
            &lt;input type="submit" name="submit" value="Edit prospect" /&gt;&amp;nbsp;or &lt;a href="#" title="Close window" onclick="Modalbox.hide()"&gt;Cancel and close window&lt;/a&gt;
            &lt;input type="hidden" name="status" value="Prospect" /&gt;
            &lt;input type="hidden" name="url_title" value="{url_title}" maxlength="75" /&gt;
            &lt;input type="hidden" name="entry_date" value="&lt;?php echo date("Y-m-d h:i"); ?&gt;" /&gt;
            &lt;input type="hidden" name="allow_comments" value="y" {allow_comments} /&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
{/exp:weblog:entry_form}</pre>
<p>Go ahead and remove the divs we created in step 5, transferring them to your new template group. Then find your &#8220;edit&#8221; link (step 4) and replace it with the following:</p>
<pre>&lt;a onclick="Modalbox.show('{path=modalboxes/edit_prospect}{entry_id}', {title: this.title, width: 800}); return false;" title="{title} &amp;ndash; Edit details" href="#"&gt;</pre>
<p>This line of code passes each weblog entry&#8217;s ID to the &#8220;modalboxes&#8221; template group, where it&#8217;s picked up automatically and used to populate your SAEF.</p>
<p>You can now enjoy modalboxes without cluttering your main templates with hidden divs. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3roadsmedia.com/blog/use-a-modal-box-to-edit-content-inline-with-expressionengine/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Inline editing with ExpressionEngine and AJAX</title>
		<link>http://www.3roadsmedia.com/blog/inline-editing-with-expressionengine-and-ajax/</link>
		<comments>http://www.3roadsmedia.com/blog/inline-editing-with-expressionengine-and-ajax/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 17:53:40 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Developer's Toolbox]]></category>
		<category><![CDATA[ExpressionEngine]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.3roadsmedia.com/?p=214</guid>
		<description><![CDATA[0]]></description>
			<content:encoded><![CDATA[<p>Web developers are a demanding lot. We&#8217;re impatient for change, we wanted it yesterday, and we love shortcuts. I don&#8217;t mean the &#8220;cutting corners&#8221; type of shortcut. I mean the &#8220;this will make life easier&#8221; type of shortcut.</p>
<p>In this post, I&#8217;ll show you how you can use AJAX to edit your ExpressionEngine content on the front end, without a page refresh, and with a simple click of the mouse.</p>
<p><strong>NOTE: I recently wrote about an improved method for inline editing with EE using modal boxes. <a href="http://www.3roadsmedia.com/blog/use-a-modal-box-to-edit-content-inline-with-expressionengine/">Read the tutorial here</a>.</strong><span id="more-214"></span></p>
<h2>The Problem</h2>
<p>Making changes to front end content can be time consuming and confusing. Even if your templates are set to display WordPress-style &#8220;edit&#8221; links next to each weblog entry, you have to use the control panel (CP) to make changes. <strong>Many end users don&#8217;t feel comfortable</strong> using the CP, and many times you just want to make a quick change without leaving the front end.</p>
<p>The good news is that with a bit of AJAX, we can bypass the CP altogether, greatly simplifying the editing process.</p>
<h2>The Solution</h2>
<p>I took my inspiration from <a href="http://24ways.org/2005/edit-in-place-with-ajax">an old post on inline editing</a> at 24 ways. I&#8217;ve modified the code to work with ExpressionEngine, and will show you how you can get it to work with your own EE site.</p>
<h3>Step 1: Create a new EE weblog and template</h3>
<p>Create a new weblog and connect it to a custom field group with at least one textarea field (<strong>make sure the formatting is set to &#8220;none&#8221;</strong>). Enter a few sample entries, and then create a new template.</p>
<p>Enter the following HTML in your template, substituting your weblog name for <strong>ajax-test</strong> and your custom field name for <strong>{body}</strong>:</p>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
    &lt;title&gt;Edit-in-Place with Ajax&lt;/title&gt;
    &lt;link rel="stylesheet" type="text/css" href="{stylesheet=home/stylesheet}" /&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;h1&gt;Editing Inline with ExpressionEngine and AJAX&lt;/h1&gt;

{if logged_in}
    {exp:weblog:entries disable="categories|member_data|pagination|trackbacks" weblog="ajax-test"}
        &lt;h2&gt;{title}&lt;/h2&gt;
        &lt;p&gt;{body}&lt;/p&gt;
    {/exp:weblog:entries}
{/if}

{if logged_out}&lt;p&gt;You must be logged in to view this page!&lt;/p&gt;{/if}
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>I recommend previewing your template to ensure the entries are displaying properly.</p>
<h3>Step 2: Grab the Prototype JavaScript library</h3>
<p>The script we&#8217;ll be using requires Prototype. <a href="http://www.prototypejs.org/download">Get the latest version of Prototype here</a>, upload it to your server, and add the following line to your template (inside the <code>&lt;head&gt;</code> tags):</p>
<pre>&lt;script src="http://path-to-your-scripts-folder/prototype.js" type="text/javascript"&gt;&lt;/script&gt;</pre>
<h3>Step 3: Grab the Script</h3>
<p>Here&#8217;s where all the magic happens. <a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/03/editinplace_basic.js">Grab the script here</a> and save it as <strong>editinplace.js</strong> (don&#8217;t upload it just yet). Be sure to place a call to the script in your template by adding this line:</p>
<pre>&lt;script src="http://path-to-your-scripts-folder/editinplace.js" type="text/javascript"&gt;&lt;/script&gt;</pre>
<p>I recommend leaving the script open in another window while you follow along here.</p>
<h3>Step 4: Get familiar with the script</h3>
<p>Let&#8217;s take a closer look at <strong>editinplace.js</strong>. The first line ensures the script won&#8217;t run until the page is fully loaded. The <code>init()</code> function defines which element ID we want to be editable &#8211; in this case, <strong>editTitle</strong>.</p>
<p>The <code>makeEditable()</code> function does three things:</p>
<ol>
<li><strong>On mouseclick</strong>, call the <code>edit()</code> function, which hides the editable text and displays a textarea and two buttons (&#8220;Save&#8221; and &#8220;Cancel&#8221;)</li>
<li><strong>On mouseover</strong>, add a CSS class to the editable area (this allows us to highlight it on hover)</li>
<li><strong>On mouseout</strong>, remove the CSS class from the editable area</li>
</ol>
<p>Notice that the <code>showAsEditable()</code> function is creating and removing a CSS class called <code>editable</code>. You can rename this to whatever you want, but <strong>be sure to add a declaration to your stylesheet</strong>.</p>
<p>The declaration I&#8217;m using on the demo page is:</p>
<pre>.editable { background:#ffffd3; cursor:pointer; }</pre>
<p>If a user clicks &#8220;Cancel,&#8221; the <code>cleanUp()</code> function is called; it clears the textarea and buttons and unhides the original text.</p>
<p>If a user clicks &#8220;Save,&#8221; the <code>saveChanges()</code> function is called; it posts the changes, displays a &#8220;Saving&#8230;&#8221; message, and returns the updated text.</p>
<h3>Step 5: Grab the PHP</h3>
<p>The script you just copied works in tandem with a small PHP script, which takes your changes and echoes them to the screen. Paste the script below into a new file:</p>
<pre>&lt;?php
    $id = $_POST['id'];
    $content = $_POST['content'];
    echo htmlspecialchars($content);
?&gt;</pre>
<p>Save this file as <strong>edit.php </strong>and upload it to your server. Update <strong>editinplace.js</strong> (line 53) to point to your PHP script, then upload this file too.</p>
<h3>Step 6: Put the script to work</h3>
<p>Now that we know what the scripts are doing, let&#8217;s put them to work. Editinplace.js is looking for an element with an ID of <strong>editTitle</strong>, but your template doesn&#8217;t currently have that. Let&#8217;s add it in.</p>
<p>Change the <code>&lt;h2&gt;</code> tag in your template to this:</p>
<pre>&lt;h2 id="editTitle"&gt;{title}&lt;/h2&gt;</pre>
<p>Save your template and preview it. Move your mouse over your <strong>first heading</strong>. Assuming you copied my CSS rules from above, you should see a highlighted box surround your heading, and your cursor should change to a pointer. Click the heading, edit the text, and click &#8220;Save&#8221; or &#8220;Cancel.&#8221;</p>
<p>If you try to edit your other headings, you&#8217;ll notice nothing&#8217;s happening.</p>
<p>Why is this? Remember that an ID is unique to a page, so if you have duplicate IDs, you&#8217;ll get strange results. In this case, <strong>only the first element of a given ID will be editable</strong>.</p>
<p>For most ExpressionEngine applications, you&#8217;ll be looping through a weblog several times, so this approach won&#8217;t work.</p>
<h3>Step 7: Making multiple items on the same page editable</h3>
<p>First, change the <code>init()</code> function in <strong>editinplace.js</strong> to this:</p>
<pre>function init() {
    var max = 50;
    for (var i = 1; i &lt;= max; i++) {
        makeEditable('editTitle_' + i);
    }
}</pre>
<p>Then, in your template, modify your <code>&lt;h2&gt;</code> tag like so:</p>
<pre>&lt;h2 id="editTitle<strong>_{count}</strong>"&gt;{title}&lt;/h2&gt;</pre>
<p>Refresh your template and you should be able to make changes to all of your headings.</p>
<h3>Step 8: Posting changes to your ExpressionEngine database</h3>
<p>Up to this point, we&#8217;ve only been echoing changes back to the screen. Now it&#8217;s time to make those changes permanent by posting them to a database.</p>
<p>The bulk of the work will come in <strong>edit.php</strong>, though before we start making changes to that file, we need to add some things to <strong>editinplace.js</strong>.</p>
<p>Update your <code>saveChanges()</code> function to look like this (changes are in <strong>bold</strong>):</p>
<pre>function saveChanges(obj) {
    var new_content = escape($F(obj.id+'_edit'));

    <strong>obj.preUpdate = obj.innerHTML</strong>
    obj.innerHTML = "Saving…";
    cleanUp(obj, true);

    var success = function(t){editComplete(t, obj);}
    var failure = function(t){editFailed(t, obj);}

    var url = 'http://path-to-your-scripts-folder/edit.php';
    var pars = 'id=' + obj.id + '&amp;content=' + new_content<strong> + '&amp;pre=' + obj.preUpdate</strong>;
    var myAjax = new Ajax.Request(url, {method:'post',
    postBody:pars, onSuccess:success, onFailure:failure});
}</pre>
<p>If you copy and paste from above, don&#8217;t forget to update the path to your PHP file.</p>
<p>Next, update <strong>edit.php</strong> to look like this:</p>
<pre>&lt;?php
    $id = $_POST['id'];
    $content = $_POST['content'];
    <strong>$pre = $_POST['pre'];</strong>
    echo htmlspecialchars($content);

<code><span class="html">    <strong>require_once("path-to-your/include.inc.php")</strong>;

</span></code><strong>    $sql = mysql_query("UPDATE exp_weblog_titles SET title = '$content' WHERE title = '$pre'");

    if(!$sql) {
        echo "&lt;p class='error'&gt;Unable to update the title!&lt;/p&gt;";
    }</strong>
?&gt;</pre>
<p>You&#8217;ll need to create an include file that contains the connection information for your database (<a href="http://www.3roadsmedia.com/blog/wp-content/uploads/2009/03/sample-include.inc.txt">grab a sample include file here</a>).</p>
<p>Update the path to your include file, enter your database connection information, save all three files, upload them, and refresh your rendered template. Make some changes to the titles. Refresh the page again, and your changes should remain.</p>
<p>Congratulations &#8211; you&#8217;ve just made a direct change to your EE database with AJAX!</p>
<h2>Going a step further &#8211; editing more than just titles</h2>
<p>You probably noticed in <a href="http://www.3roadsmedia.com/ajax-demo.html">the demo</a> that the excerpt for each post was also editable. Here&#8217;s how you do it:</p>
<h3>Step 9: Create another editable element</h3>
<p>First, you&#8217;ll need to tell the script that you want to make another set of IDs editable. Modify the <code>init()</code> function in <strong>editinplace.js</strong> to look like this:</p>
<pre>function init() {
    var max = 50;
    for (var i = 1; i &lt;= max; i++) {
        makeEditable('editTitle_' + i);
        <strong>makeEditable('editBody_' + i);</strong>
    }
}</pre>
<p>Next, modify your template by adding the new ID:</p>
<pre>&lt;p<strong> id="editBody_{count}"</strong>&gt;{body}&lt;/p&gt;</pre>
<p>Finally, to post any changes to your paragraphs to the database, you&#8217;ll need to modify <strong>edit.php</strong>:</p>
<pre>&lt;?php
    $id = $_POST['id'];
    $content = $_POST['content'];
    $pre = $_POST['pre'];
    echo htmlspecialchars($content);

<code><span class="html">    require_once("path-to-your/include.inc.php");</span></code>

<strong>    if(stristr($id, 'Title') == true) {
        $sql = mysql_query("UPDATE exp_weblog_titles SET title = '$content' WHERE title = '$pre'");
    } elseif(stristr($id, 'Body') == true) {
        $sql = mysql_query("UPDATE exp_weblog_data SET field_id_65 = '$content' WHERE field_id_65 = '$pre'");
    }</strong>
?&gt;</pre>
<p>Since the PHP script is handling requests for both <code>editTitle</code> and <code>editBody</code>, we need to use the <code>stristr()</code> function to determine which ID is being passed in.</p>
<p><strong>Be sure that the field ID matches your custom field! </strong>In the example above, it is 65, but yours is likely different.</p>
<p>You can find your field ID by going into the CP, clicking &#8220;Admin,&#8221; selecting &#8220;Custom Weblog Fields,&#8221; and hovering your mouse over the field name on the left. The field ID will appear at the very end of the URL string at the bottom left of your browser.</p>
<h3>Step 10: Provide a textarea for paragraphs and a text input for titles</h3>
<p>You probably don&#8217;t want to be editing large hunks of text in a tiny input box. To get a textarea to show up when you click on a paragraph (while keeping a text input for your titles), modify the <code>edit()</code> function in <strong>editinplace.js</strong>:</p>
<pre>function edit(obj) {
    Element.hide(obj);

<strong>    if(obj.id.search(/Title/) != -1) {
        // show an input box if we're editing a header
        var textbox ='&lt;div class="edit-input" id="' + obj.id + '_editor"&gt;&lt;input name="' + obj.id + '" type="text" id="' + obj.id + '_edit" value="' + obj.innerHTML + '" /&gt;';
    } else {
        // else show a textarea
        var textbox ='&lt;div class="edit-area" id="' + obj.id + '_editor"&gt;&lt;textarea name="' + obj.id + '" id="' + obj.id + '_edit"&gt;' + obj.innerHTML + '"&lt;/textarea&gt;';
    }</strong>

    var button = '&lt;input type="button" value="SAVE" id="' + obj.id + '_save"/&gt; OR &lt;input type="button" value="CANCEL" id="' + obj.id + '_cancel"/&gt;&lt;/div&gt;';

    new Insertion.After(obj, textbox+button);

    Event.observe(obj.id+'_save', 'click', function(){saveChanges(obj)}, false);
    Event.observe(obj.id+'_cancel', 'click', function(){cleanUp(obj)}, false);
}</pre>
<h3>Step 11: Limiting edits to certain member groups</h3>
<p>Before you decide to go crazy with inline editing, remember that, without the proper checks, anyone who visits your site can make changes to your content.</p>
<p>For starters, you should wrap your editable areas in a <code>{if logged_in}</code> conditional. Once that&#8217;s done, you should also consider only allowing certain member groups to edit content inline. Here&#8217;s a quick fix:</p>
<pre>&lt;h2<strong>{if member_group == 1}</strong> id="editTitle_{count}"<strong>{/if}</strong>&gt;{title}&lt;/h2&gt;</pre>
<p>These conditionals allow you to specify who can edit which areas. You could, for example, allow members to edit your body text, but only allow admins to edit your titles.</p>
<h2>Limitations</h2>
<p>While working through this script, I came up against a few roadblocks:</p>
<ul>
<li>When making more than one element (e.g., headers <strong>and </strong>paragraphs) editable, you must have an equal number of each. In other words, if there are 3 headers on the page that you want to edit, you can&#8217;t have more than 3 paragraph blocks that are editable. Paragraphs beyond the 3rd won&#8217;t be clickable.</li>
<li>You have to pre-define a max number of editable fields (in my example, this is 50).</li>
<li>Inline editing doesn&#8217;t work well with headings that are also anchors</li>
</ul>
<h2>Conclusion</h2>
<p>This is my first attempt at getting inline editing to work with ExpressionEngine. I don&#8217;t profess to be a code guru, so it is my hope that a little bit of discussion can help improve the code here and make life easier for developers and end users everywhere.</p>
<p>I welcome your feedback, frustrations, and success stories. Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3roadsmedia.com/blog/inline-editing-with-expressionengine-and-ajax/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
