<?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>larryaronson.com &#187; jQuery</title>
	<atom:link href="http://larryaronson.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://larryaronson.com</link>
	<description>Systems Psychoanalyst</description>
	<lastBuildDate>Wed, 14 Dec 2011 04:17:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Editable Content and Local Storage in HTML5</title>
		<link>http://larryaronson.com/2010/editable-content-and-local-storage-in-html5/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://larryaronson.com/2010/editable-content-and-local-storage-in-html5/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 19:32:45 +0000</pubDate>
		<dc:creator>Larry Aronson</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[contenteditable]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[notepad]]></category>
		<category><![CDATA[webstorage]]></category>

		<guid isPermaLink="false">http://larryaronson.com/?p=1247</guid>
		<description><![CDATA[A demo showing how to build a <em>Notepad</em> widget using new HTML5 features: content editable, and webstorage. The Notepad provides the ability to keep a list of private notes associated with a webpage.  ]]></description>
			<content:encoded><![CDATA[<p>A lot of the noise around HTML5 has been about whether or not it will replace Flash as the primary means of delivering video content over the Web. While I believe that HTML5&#8242;s simple, native <em>video</em> element is superior to Flash&#8217;s plugin-based mess of <em>object, embed </em>and<em> param</em> elements, Flash isn&#8217;t going away anytime soon. The noise, however, drowns out information about other interesting HTML5 features, two of which, content editable-ness and local storage, I&#8217;ll explore in this article with a simple example. Google&#8217;s Chrome browser supports both of these features; other browsers support one or the other, or neither.</p>
<p><img src="http://larryaronson.com/wp-content/uploads/imgres.jpeg" alt="Local Storage" title="Open Container" width="259" height="194" class="alignleft size-full wp-image-1287" />Let&#8217;s say you have a page on your website and you would like to offer your readers the ability to jot down notes related to the content of that page in some kind of input field. Furthermore, since you expect visitors to revisit the page from time to time, you&#8217;d like to store their notes somewhere so that the input field can be loaded when they next load the page. Before HTML5, you would either use a server-side process, cookies or some combination of the two to make this happen. With HTML5, there&#8217;s a third choice: the <em>localStorage</em> window object.</p>
<p>First, let&#8217;s start with the input field. We could use a <em>textarea</em> element but in HTML5, any element can be turned into an input element by adding the <em>contenteditable</em> attribute:</p>
<pre style="color:#007f00">
&lt;ul id="notepad" contenteditable="true">
  &lt;li>&lt;/li>
&lt;/ul>
</pre>
<p>In the  CSS for this list element, we want to set its size and position:</p>
<pre style="color:#007f00">#notepad {
 height: 20%;
 width: 20%;
 display: none;
 position: fixed;
 top: 0.5in; right: 0.5in;
 overflow: auto;
 padding: 1em;
 border: thin solid;
 list-style-type: none;
 background-color: #fffff0; /* light yellow */
}</pre>
<p>This will place the list element 1/2 inch down and in from the top-right corner of the browser&#8217;s window. The bordered box will take up 1/5 of the window&#8217;s width and height and scrolling will be enabled if there is more content then fits. The <em>display</em> property is set to &#8220;none&#8221; initially. The user will be able to make the notepad list visible by clicking a button with an <em>onclick</em> handler.</p>
<pre style="color:#007f00">&lt;button id="notepad_toggle"
        onclick="$('#notepad').toggle()">Notepad&lt;/button></pre>
<p>I&#8217;m using jQuery for the <em>onclick </em>handler because it makes it easy to target elements<em> </em>. If you copy this code, make sure you load jQuery somewhere in the document&#8217;s head.</p>
<p>HTML5 extends the <em>window</em> object with the <em>localStorage</em> property and two primary methods: <em>setItem(name, value)</em> and <em>getItem(name)</em> to set and retrieve name/value pairs of data items. Any number of such items can be stored with a webpage and each page&#8217;s storage object is independent of any other page&#8217;s. Unlike cookies, local storage items are never sent by the browser to the server and thus provides a efficient means of saving page state information even for megabyte data items.</p>
<p>For our example, we can store the contents of the notepad element each time it is changed. We will do this with the blur method, detecting when the user leaves the notepad to do something else. Here&#8217;s some jQuery that does that nicely:</p>
<pre style="color:#007f00">$('#notepad').blur(function () {
  localStorage.setItem('notepad', this.innerHTML);
});</pre>
<p>How nice is that? The storage doesn&#8217;t have to be initialized; it&#8217;s just there waiting for you to throw something into it.  </p>
<p>When the page is first loaded we need to check if the notepad contents has been saved from some previous visit by this browser and if so, use the stored value to replace the inner contents of the list. This can be done with the following JavaScript statement:</p>
<pre style="color:#007f00">  if ( localStorage.getItem('notepad') ) {
    var notepad = document.getElementById('notepad');
    notepad.innerHTML = localStorage.getItem('notepad');
  }</pre>
<p>Note that there&#8217;s no conflict in the three uses of &#8216;notepad&#8217; in the code above. The name for the local variable can be anything as can the name of the stored data item. Neither has to be the same as the UL element&#8217;s ID. Hopefully, I&#8217;m avoiding confusion by naming everything &#8216;notepad&#8217; and not adding any.</p>
<p>Since this is only going to work on some browsers, let&#8217;s test to see if local storage is available. If it isn&#8217;t,  we can just hide the the button that makes the notepad visible.</p>
<pre style="color:#007f00">if (!window.localStorage) $('#notepad_toggle').hide();</pre>
<p>or, for debugging, we can call an <em>alert</em> message.</p>
<p>All of the code can go into a script element embedded in the content body, like this blog post, for example:</p>
<p><button id="notepad_toggle" onclick="$('#notepad').toggle('slow')" style="padding: 0.5em;">Notepad</button><br />
<script type="text/javascript">$(document).ready(function () { if ( window.localStorage ) { if ( localStorage.getItem('notepad') ) { var notepad = document.getElementById('notepad'); notepad.innerHTML = localStorage.getItem('notepad'); } $('#notepad').blur(function () { setItem('notepad', this.innerHTML); }); } else { $('#notepad_toggle').hide(); } });</script></p>
<p>Click the button above and enter anything in the light yellow notepad that opens in the top right corner of your HTML5 capable browser.  Enter anything you want – I&#8217;ll never see it, nor will anyone else. What&#8217;s entered in your local storage stays in your local storage. Try dragging and dropping images, tables, links and other thingys. Notice something interesting? You can&#8217;t use HTML to markup your own typing but anything you drag or paste in retains all of its HTML formatting. Now Go Away! Come back to this page sometime later (with the same browser) and click the notepad button again. There&#8217;s your stuff!  </p>
<p><a href="javascript:void(0);#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed" onclick="$('#localStorage_code').slideDown('slow')">Click here to see the code</a> for a stand-alone demo to get you started.</p>
<div id="localStorage_code" style="display:none;">
<pre style="font-size: 11px; color:#007f00">
&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;Notepad Demo&lt;/title&gt;
&lt;!-- (c) 2010 by Larry Aronson --&gt;
&lt;style&gt;
    body  { padding: 36px; }
    #notepad {
     height: 20%;
     width: 20%;
     display: none;
     position: fixed;
     top: 0.5in; right: 0.5in;
     overflow: auto;
     padding: 1em;
     border: thin solid;
     list-style-type: none;
     background-color: #fffff0; /* light yellow */
    }
&lt;/style&gt;

&lt;!-- let's get our jQuery from Google --&gt;
&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;
&lt;/script&gt;
&lt;script&gt;
    $(document).ready(function () {
      if ( window.localStorage ) { 	// see if webstorage is working
        if ( localStorage.getItem('notepad') ) {
          var notepad = document.getElementById('notepad');
          notepad.innerHTML = localStorage.getItem('notepad');
        }
        $('#notepad').blur(function () {	// save when exiting the notepad
          localStorage.setItem('notepad', this.innerHTML);
        });
      }
      else {
        $('#notepad_toggle').hide(); 	// hide button if no webstorage
      }
    });
&lt;/script&gt;
&lt;/head&gt;  

&lt;body&gt;
  &lt;button id="notepad_toggle"
  	  onclick="$('#notepad').toggle('slow')"&gt;Notepad&lt;/button&gt;
&lt;ul id="notepad" contenteditable="true"&gt;
&lt;li&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
</div>
<ul id="notepad" contenteditable="true" style="height: 20%; width: 20%; display: none; position: fixed; top: 0.5in; right: 0.5in; overflow: auto; padding: 1em; border: thin solid; list-style-type: none; background-color: #fffff0;">
<li> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://larryaronson.com/2010/editable-content-and-local-storage-in-html5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Profoto-USA rebuilt</title>
		<link>http://larryaronson.com/2010/profoto-usa-rebuilt/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://larryaronson.com/2010/profoto-usa-rebuilt/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 13:33:14 +0000</pubDate>
		<dc:creator>Larry Aronson</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MAC Group]]></category>
		<category><![CDATA[Matt Hill]]></category>
		<category><![CDATA[Ron Egatz]]></category>
		<category><![CDATA[slideshow]]></category>

		<guid isPermaLink="false">http://larryaronson.com/?p=1202</guid>
		<description><![CDATA[<a href="/2010/profoto-usa-rebuilt"><img class="alignleft size-thumbnail wp-image-1209" title="profoto-usa screenshot" src="http://larryaronson.com/wp-content/uploads/blog.profoto-usa_screenshot.png" alt="Screen shot of Profoto-USA home page " width="75" height="63" /></a>Repairing and rebuilding Profoto-USA's blog on photographic lighting techniques and equipment. This was a fun job as I got to learn how to replace Wordpress 2 theme technology with WP 3.0 functions and features. ]]></description>
			<content:encoded><![CDATA[<p>Ron Egatz and I go back to the time before the Web. He is one of those all-around creatives who does writing, editing, photography, graphic design and some Web programming. He occasionally calls on me to solve some of the more technical problems he encounters. So I was pleased when he asked me to help one of his associates, Matt Hill of <a href="http://MacGroupus.com/" target="_blank">MAC Group</a>, who needed a blog repaired ASAP.</p>
<p>Someone had started a blog for <a href="http://blog.profoto-usa.com/" target="_blank">Profoto-USA</a> using a customized theme but left it an unfinished mess. The sidebar was all screwed up, the <em>more</em> tag wasn&#8217;t working, there were no social-sharing functions and no control over the main menu – to name just a few of the problems. Profoto-USA is about the importance of good <strong>photographic lighting</strong> with dozens of interesting articles (some of the best authored by Ron) illustrated with beautiful photographs. Please click the screenshot below to check it out.</p>
<p><a href="http://blog.ProFoto-USA.com/"><img class="alignright size-full wp-image-1209" title="profoto-usa screenshot" src="http://larryaronson.com/wp-content/uploads/blog.profoto-usa_screenshot.png" alt="Screen shot of Profoto-USA home page " width="250" height="210" /></a>Fixing the sidebar, installing social sharing widgets and enabling the WP 3.0 menu manager was straight forward. The real challenge was finding a way to give authors more control over the content. The <em>more</em> tag, mentioned above, provides the ability to place a marker in a post so that on the blog&#8217;s front page, the post is displayed up to the marker, followed by a link to the rest of the article. I got that working but it wasn&#8217;t enough to manage the huge amount of content. The beginning paragraphs of a post often do not make the best summary, especially with long magazine-style articles. WordPress provides the ability to hand-craft a article summary, called an <em>excerpt</em>, but this feature has to be coded into the theme. Some themes show post excerpts on their front page; some show full posts (up to the first more tag.) I decided to give Profoto-USA the choice of which to use on a per-post basis using a custom field.</p>
<p>The previous developer had hard-coded a modified <em>Recent Posts</em> sidebar widget that showed, for each post, the post title and a linked thumbnail image. The thumbnails are large: 304 x 190 pixels, and only the first two or three appeared &#8220;above the fold.&#8221; The obvious solution was to use a sideshow plugin that cycled through the thumbnail photographs. Now, I&#8217;ve used a number of such plugins before and the general problem with them is that they only do what the plugin author designed them to do plus whatever user configurable options that author cares to code in. Imho – most of them fall short. Since most of the code for fetching the post data was already working, I decided to use some jQuery to add the animation effects and navigation controls to make it into a sideshow  (<a onclick="$('#slide-show-example').toggle('slow');" href="javascript:void(0);#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">click for nerdy technical details.</a>)</p>
<div id="slide-show-example" style="display: none; padding: 1em; border: thin solid; background-color: #f0fff7; font-size: .9em; line-height: 1.1em;">
<p style="text-align: right;">[<a onclick="$('#slide-show-example').toggle('slow');" href="javascript:void(0);#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><em style="color: red;">close</em></a>]</p>
<p>The code in the sidebar generated a structure which looked like this:</p>
<pre>
&lt;div id="post-slides"&gt;
    &lt;div class="post-slide"&gt;  &lt;!-- first slide --&gt;
        &lt;a href=..." title="..."&gt;&lt;img ... /&gt;&lt;/a&gt;
        &lt;h3&gt;&lt;a href=".." title="..."&gt;...&lt;/a&gt;&lt;/h3&gt;
    &lt;/div&gt;

    &lt;div class="post-slide"&gt;  &lt;!-- second slide --&gt;
        ...
    &lt;/div&gt;

    ...
&lt;/div&gt;</pre>
<p>The <a href="http://jquery.malsup.com/cycle/" target="_blank">jQuery cycle plugin</a> will apply an effect successively to each first-level child element of a selected parent. The type of effect, the timing and other options are passed as parameters. So, all that had to be done to make the above into a slideshow was to place the following script element just after the above code in the sidebar template.</p>
<pre>&lt;script type="text/javascript"&gt;
    $(document).ready(function() {
        $('#post-slides').show().cycle({
            fx: 'fade',
            speed: 1000,
            timeout: 10000,
            next: '#next_slide',
            prev: '#prev_slide'
        });
    });
&lt;/script&gt;</pre>
<p>Besides <em>fade</em>, other effects include: <em>slideUp</em>, <em>slideDown</em>, <em>slideLeft</em> <em>slideRight</em> and many more. The <em>speed</em> and <em>timeout</em> options are given in miliseconds. The <em>next</em> and <em>prev</em> options are given the ids of elements that will serve as the slideshow controls. I positioned double angle brackets in the widget title with this code placed above the post-slides division:</p>
<pre>&lt;h4&gt;Recent Articles&lt;/h4&gt;
 &lt;div id="slideshow-nav"&gt;
   &lt;div id="prev_slide"&gt;
     &lt;a href="#" title="previous article"&gt;&amp;lt;&amp;lt;&lt;/a&gt;
   &lt;/div&gt;
   &lt;div id="next_slide"&gt;
     &lt;a href="#" title="next article"&gt;&amp;gt;&amp;gt;&lt;/a&gt;
   &lt;/div&gt;
 &lt;/div&gt;</pre>
<p>Here&#8217;s a closeup image of the slideshow.</p>
<p><img class="alignnone size-full wp-image-1213" title="Profoto slideshow" src="http://larryaronson.com/wp-content/uploads/Profoto_slideshow.png" alt="" width="346" height="284" /></p>
</div>
<p>This took much less time than I anticipated – less time than it would have taken to find and configure a plugin to the client&#8217;s specifications. With the extra time on my hands, I decided to give Profoto-USA a feature they didn&#8217;t ask for but felt the site definitely needed: <a href="http://blog.profoto-usa.com/?page_id=1972" target="_blank">an index to <em>all</em> articles</a> showing only the permalinked titles and the meta-info line with author and publication date. I added it to the footer menu without telling them about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://larryaronson.com/2010/profoto-usa-rebuilt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding more content with less clutter</title>
		<link>http://larryaronson.com/2009/adding-more-content-with-less-clutter/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://larryaronson.com/2009/adding-more-content-with-less-clutter/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 21:46:47 +0000</pubDate>
		<dc:creator>Larry Aronson</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[Advanced Tooltips]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[random quotes]]></category>
		<category><![CDATA[UI Tools]]></category>

		<guid isPermaLink="false">http://larryaronson.com/?p=990</guid>
		<description><![CDATA[<a href="adding-more-content-with-less-clutter"><img width="75" height="75" src="http://larryaronson.com/wp-content/uploads/Kate-Nasser.png" alt="" class="alignleft wp-image-1047" /></a>For my client Kate Nasser's website, I made a number of changes to add more features &#38; content, reduce clutter and improve search engine optimization (SEO). This article shows how to use advanced tooltips to make suplimental information invisible until needed. ]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a fundamental conflict in web page design between content and clutter. We want more content to make our pages findable &amp; provide value to visitors while maintaining visually clear layouts so as not to frighten away seekers of simple truths. The key to solving this conundrum is to stop thinking of web pages as printed page emulators. A printed page is a fixed matrix of tiny colored dots (pixels) on a two-dimensional surface. A web page is a dynamic document object composed of multiple layers of interactive elements.</p>
<p><img id="kn1" class="alignright" src="http://katenasser.com/wp-content/themes/katenasser/screenshot.jpg" alt="" width="200" height="213" title="Kate Nasser's front page as of November, 2009" />My client, Kate Nasser – the people skills coach, has grown her consulting business by consistently adding content to her blog/website and by using <a href="http://twitter.com/katenasser">Twitter</a>, <a href="http://linkedin.com">LinkedIn</a> and <a href="http://www.youtube.com/user/KateNasser">youTube</a> to draw traffic. A recent SEO/SEM assessment of her site recommended adding more keyword-rich content and reducing some of front page&#8217;s  clutter.  This is what the page looked liked.</p>
<h3>Advanced Tooltips.</h3>
<p>We had a box on the right side of the content area listing a dozen &#8220;Needs&#8221; linked to different site pages or posts. With each need there was an associated comment (technically, a definition list.) We decided to move the box to the left side of the page (ahead of the straight text content,) placing the comment parts in tooltip boxes that appear as you mouse over the topic part. Kate was free to add more content to the hidden (only from humans) comment parts.</p>
<p>Tooltips are the little yellow boxes that appear when your mouse hovers over a link. The content of the tooltip box is taken from the title attribute of the HTML tag that creates the link. But ordinary tooltips are boring with fixed style and color; yellow wasn&#8217;t the best choice given the site&#8217;s aqua tones.</p>
<p>So, I installed <a href="http://flowplayer.org/tools/" target="_blank">JQuery Tools from Flowplayer.org</a> which has an easy to use, advanced tooltip tool. JQuery is a library of Javascript functions that make it easy to add dynamic behavior to Web page elements without having to worry about cross-browser incompatibilities. JQuery Tools is a free, lightweight tool collection that provides basic behaviors to attach to any page element. The Advanced Tooltip tool replaces the browser&#8217;s builtin tooltip and can be attached to any page element, not just links.</p>
<p>To make Advanced Tooltips work, you have to provide a page element with a unique id to hold the content. It doesn&#8217;t matter where it&#8217;s placed. The element, typically a division, is dynamically positioned near the moused-over element. The element is re-useable; you only need one holder element for all tooltips of a given style on a page. The tooltip is styled using Normal CSS so I was able to match the colors and typography of that section of the site&#8217;s front page.</p>
<h4 id="kn2" title="Click &lt;em&gt;expand&lt;/em&gt; to display the technical details of using advanced tooltips.  The &lt;em&gt;close&lt;/em&gt; link is at the end of the section.">Technical Details <small>(<a onclick="$('#TechDetails').slideDown();" href="javascript:void(0);#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">Expand</a>)</small></h4>
<div id="TechDetails" style="display:none; color:#666; font-size: 90%;">
<p>On KateNasser.com&#8217;s front page (id=2,) tooltips will be activated for all links that are inside level 3 headings in the css class, <em>need-title</em>. This bit of <span style="color: #993300;">HTML</span>, <span style="color: #008000;">PHP</span> and <span style="color: #0000ff;">jQuery</span> coding was added to the document head in the header template.</p>
<pre id="line21" class="SmallCode"><span style="color: #993300;">&lt;script src="http://cdn.jquerytools.org/1.1.2/jquery.tools.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;</span><span style="color: #008000;">
&lt;?php if (is_page("2")) { ?&gt;</span>
<span style="color: #0000ff;">    $(document).ready(function() {
        $("h3.need-title a").tooltip({ tip: "#TipBox",
                                       offset: [-25, 150],
                                       effect: 'fade' });
    });</span><span style="color: #008000;">
&lt;?php } ?&gt;</span>
<span style="color: #993300;">&lt;/script&gt;</span></pre>
<p>The first line brings in the jQuerytools library, including the latest version of jQuery. Flowplayer.org encourages developers to directly link to their high-performance server to get the latest version. However, you can also download the library and install in on your own site for more control.</p>
<p>The <span style="color: #008000;">PHP</span> code makes sure that the tooltip code is executed only on the page we want it to. And, the <span style="color: #0000ff;">jQuery</span> code attaches the tooltips to their triggers and provides some options. JQuery does this after the document is fully defined and &#8220;ready&#8221;. This is typical of jQuery usage.</p>
<p>The holding container is defined in <span style="color: #993300;">HTML</span> at the end of content using the WordPress editor. All it contains is a non-breaking space. Note how the jQuery code above refers to this element using a CSS selector syntax.</p>
<pre id="line314" class="SmallCode"><span style="color: #993300;">&lt;div id="TipBox" class="needs-tips"&gt;&amp;nbsp;&lt;/div&gt;</span></pre>
<p>Finally, in the template style sheet, <em>styles.php</em>, the following <span style="color: #800080;">CSS</span> style rules are used:</p>
<pre class="SmallCode"><span style="color: #800080;">#TipBox {
 display:none;
 width: 200px;
}</span></pre>
<pre class="SmallCode"><span style="color: #800080;">.needs-tips {
 text-align: left;
 background-color: #fafcfb;
 border: 2px solid #009ea0;
 font: italic 10pt comic sans ms;
 color: #000;
 padding: 3px 8px;
}
</span></pre>
<p align="right" id="kn3" title="This expand/collapse behavior is another example of jQuery UI tools.">(<a onclick="$('#TechDetails').slideUp();" href="javascript:void(0);#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">Close</a>)</p>
<hr size="1" /></div>
<h3>Random Quotes</h3>
<p>Kate has a bunch of her own quotes and was updating her front page every few days with a new quote from the collection. She asked if there were some way to automate the process. I browsed the various code and plugin collections and found noting simple or suitable. I decided to write my own.</p>
<p><a href="http://katenasser.com"><img id="kn4" title="This is Kate Nasser's new front page with more content and less clutter." src="http://larryaronson.com/wp-content/uploads/Kate-Nasser.png" alt="" title="Kate Nasser" width="200" height="220" class="alignleft size-full wp-image-1047" /></a>I copied her front page as a new draft page and cloned the default page template and assigned it to the new page. Thus, I was able to work on and test the new features without endangering the site&#8217;s current front page.  The cloned template would contain custom code to randomly pick a quote and place it at the beginning of the content area. The quotes themselves would be stored (and editable) as custom fields for that page with the key, &#8220;quote&#8221;.</p>
<pre class="SmallCode"><span style="color: #008000;">&lt;?php
    $todaysquote = '';
    $quotes = get_post_meta('2', 'quote');
    if (!empty($quotes)) {
        $todaysquote = $quotes[rand(0, sizeof($quotes) - 1)];
    }
?&gt;
</span><span style="color: #993300;">&lt;div class="dailyquote"&gt;&amp;ldquo;</span><span style="color: #008000;">&lt;?php _e($todaysquote); ?&gt;</span><span style="color: #993300;">&amp;rdquo;
&lt;span&gt;&amp;mdash;</span>Kate Nasser<span style="color: #993300;">&lt;/span&gt;&lt;/div&gt;</span></pre>
<p>First, a <span style="color: #008000;">PHP</span> variable, <em>$todaysquote</em>, is initialized. Then the WordPress function, <em>get_post_meta()</em>, gets all custom fields from post number 2 (that&#8217;s the front page) with key = &#8216;quote&#8217;. The values are returned as an array of strings and assigned to the variable, <em>$quotes</em>. If it&#8217;s not empty, the built-in, PHP random number generator picks one of its array items. Finally, the last two lines define the <span style="color: #800000;">HTML</span> division element that will hold the quote,  enclosing it in smart quote marks and adding Kate&#8217;s signature. Note the use of the special echo function,  <em>_e($todaysquote)</em>,  to encode any HTML characters that might be in the quote string.</p>
<p>One of the upsides of this technique is that a new front page is seen in most every visit to the front page including those by search engine robots. Over time, this can expand the number of keywords associated with the page. Unfortunately, there&#8217;s no easy way to measure which quotes work best. If you do add random content like this to a page, you should check to see if you have a caching plug-in active. You might want to exclude that page from the cache.</p>
<p>I added this feature as a template hack because my client only wanted it on one page which already had a customized template. It could be easily generalized and added as a filter to the theme&#8217;s functions file, for example, to append a random quote to post content when generating a single-post view.</p>
<div id="knTips" style="width:30%; border: 2px solid #900; background-color: #f6f6fc; color: #306; margin: 1em; padding: 1em; font-size: 90%;">&nbsp;</div>
<p><script type="text/javascript">$("#kn1,#kn2,#kn3,#kn4").tooltip({ tip: "#knTips", offset: [-25, -75] });</script></p>
]]></content:encoded>
			<wfw:commentRss>http://larryaronson.com/2009/adding-more-content-with-less-clutter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

