<?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>Themocracy WordPress Themes &#187; javascript</title>
	<atom:link href="http://themocracy.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://themocracy.com</link>
	<description>WordPress Theme Design</description>
	<lastBuildDate>Thu, 18 Aug 2011 07:34:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>A Flickr Badge using WordPress Shortcodes</title>
		<link>http://themocracy.com/2010/03/a-flickr-badge-using-wordpress-shortcodes/</link>
		<comments>http://themocracy.com/2010/03/a-flickr-badge-using-wordpress-shortcodes/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 11:22:30 +0000</pubDate>
		<dc:creator>Barrie</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=271</guid>
		<description><![CDATA[Flickr provides a neat little snippet of javaScript to supply various image galleries direct to your site - a so-named Flickr badge. Here's a good way using WordPress shortcodes to grab a gallery...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2010%2F03%2Fa-flickr-badge-using-wordpress-shortcodes%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F03%2Fa-flickr-badge-using-wordpress-shortcodes%2F" height="61" width="51" /></a></div><p><img src="http://themocracy.com/wp-content/uploads/2010/03/flickr-wordpress.jpg" alt="Flickr" title="flickr-wordpress" width="160" height="148" class="alignright size-full wp-image-272" /><strong>Flickr provides a neat little snippet of javaScript to supply various image galleries direct to your site &#8211; a so-named Flickr badge.</strong></p>
<p>So if your gallery is on Flickr &#8211; rather in your WordPress, which has its own gallery shortcode &#8211; a shortcode in the blog post content can be used to embed a gallery of thumbnail images, which is also a good way to demonstrate the various usages of WordPress shortcodes.</p>
<p>The HTML for a flickr badge looks something like this:-</p>
<pre class="brush: html">

&lt;div class=&quot;flickr_badge&quot;&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.flickr.com/badge_code_v2.gne?count=5&amp;display=latest&amp;size=m&amp;layout=h&amp;source=all_tag&amp;tag=fish&quot;&gt;&lt;/script&gt;&lt;/div&gt;
</pre>
<p>And the parameters work like this:-</p>
<p><strong>count</strong> <em> integer</em> 1-10. Default is 10.</p>
<p><strong>display</strong> <em>string</em> &#8216;latest&#8217; or &#8216;random&#8217;  Default is latest. </p>
<p><strong>layout</strong> <em>string</em> h, v, x - Photos are listed horizontally, vertically, or no style. Default is horizontal.  </p>
<p><strong>source</strong> <em>string</em> user, user_tag, user_set, group, group_tag, all, all_tag </p>
<p>Source implies which &#8216;account&#8217; the photos come from:- a specified user, a user set, a group, or all users, then filtered by tag if required.  Further parameters may then be required, user(ID string)  tag (string), group (integer), and set (integer,  the url …/sets/1234567/).  </p>
<p><strong>size</strong> <em>string</em> s, t, m   s stands for square (cropped, not small&#8230;), t for thumbnail, and m for medium.  t = thumbnail is the default.</p>
<p>(<a href="http://idgettr.com/">idgettr</a> is very useful for figuring out user IDs and the IDs for photosets, groups etc.)</p>
<p><strong>WordPress Shortcodes</strong></p>
<p>A shortcode has a &#8220;handler function&#8221; &#8211; which is integrated into the code by calling the function <strong>add_shortcode()</strong>. The purpose here is to supply the various parameters for our Flickr badge as parameters of the function &#8211; the query string for the Flickr call is then constructed and the javascript code output to the page.</p>
<p>In <strong>functions.php</strong></p>
<pre class="brush: php">

function flickr_badge_shortcode($atts){

//Here&#039;s our defaults
$query_atts = shortcode_atts(array(&#039;count&#039; =&gt; &#039;6&#039;, &#039;display&#039; =&gt; &#039;latest&#039;, &#039;source&#039; =&gt; &#039;user&#039;, &#039;size&#039; =&gt; &#039;t&#039;, &#039;user&#039; =&gt; &#039;&#039;, &#039;layout&#039; =&gt; &#039;x&#039;, &#039;tag&#039; =&gt; &#039;&#039;, &#039;group&#039; =&gt; &#039;&#039;, &#039;set&#039; =&gt; &#039;&#039;), $atts); 

 	return sprintf(&#039;&lt;div class=&quot;flickr_badge&quot;&gt;&lt;script src=&quot;http://www.flickr.com/badge_code_v2.gne?%s&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;&lt;/div&gt;
&#039;, http_build_query($query_atts));
}

add_shortcode(&#039;flickrbadge&#039;, &#039;flickr_badge_shortcode&#039;);
</pre>
<p>Provided you have PHP5 on the server, <strong>http_build_query()</strong> is the quick and easy way of building a query string from an array &#8211; and it&#8217;s urlencoded&#8230;.</p>
<p>Note that the empty parameters group, set etc. are required in the defaults &#8211; otherwise nothing gets passed to the constructed url via shortcode_atts().</p>
<p>So now, in a post content you can apply the shortcode tag:</p>
<p><strong>[flickrbadge count="4" layout="h" display="latest" size="t" source="all_tag" tag="fish"]</strong></p>
<p>And you should get a nice gallery of Flickr images for users to check out &#8211; once you&#8217;ve added some CSS to style the images (note the possible uses of the layout parameter here).</p>
<p>This example was of the selfclosing shortcode tag &#8211; but you can elaborate a bit, to inject more content into the shortcode function. The simplest example would be to give the gallery a custom title.</p>
<p>Again in functions.php</p>
<pre class="brush: php">

function flickr_badge_shortcode($atts, $content=NULL){

//Here&#039;s our defaults
$query_atts = shortcode_atts(array(&#039;count&#039; =&gt; &#039;6&#039;, &#039;display&#039; =&gt; &#039;latest&#039;, &#039;source&#039; =&gt; &#039;user&#039;, &#039;size&#039; =&gt; &#039;t&#039;, &#039;user&#039; =&gt; &#039;&#039;, &#039;layout&#039; =&gt; &#039;x&#039;, &#039;tag&#039; =&gt; &#039;&#039;, &#039;group&#039; =&gt; &#039;&#039;, &#039;set&#039; =&gt; &#039;&#039;), $atts);

return sprintf(&#039;&lt;div class=&quot;flickr_badge&quot;&gt;&lt;h3&gt;%s&lt;/h3&gt;&lt;script src=&quot;http://www.flickr.com/badge_code_v2.gne?%s&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;&lt;/div&gt;&#039;, $content, http_build_query($query_atts));
}

add_shortcode(&#039;flickrbadge&#039;, &#039;flickr_badge_shortcode&#039;);
</pre>
<p>And would be called from the post content with opening and closing shortcode tags:</p>
<p><strong>[flickrbadge count="4" layout="h" display="latest" size="t" source="all_tag" tag="fish"]Here&#8217;s the latest fish[/flickrbadge]</strong></p>
<p><strong>Caution!</strong><br />
Best to avoid camelCase notation in the attributes &#8211; the regex that the content is passed through to locate shortcodes  is case-insensitive.<br />
Always remember to use <strong>return</strong> in the handler function and not <strong>echo</strong>  (in this example sprintf, not printf). It&#8217;ll appear on the page &#8211; but not in the right place&#8230;</p>
<p>WordPress shortcodes are relatively simple in concept, but can be a bit fiddly in practice, keeping track of the default parameters and the use of  shortcode_atts() just needs a bit of thinking about sometimes&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/03/a-flickr-badge-using-wordpress-shortcodes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using JSON with WordPress</title>
		<link>http://themocracy.com/2010/02/json-wordpress/</link>
		<comments>http://themocracy.com/2010/02/json-wordpress/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 13:16:33 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=258</guid>
		<description><![CDATA[With the popularity of jQuery, AJAX, and client-side programming operations in general, there's more use made of JSON as a format for getting data backwards and forwards. 

For example, the Twitter API offers data as JSON  - and more manageably than accessing their RSS XML feeds for user timelines.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fjson-wordpress%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fjson-wordpress%2F" height="61" width="51" /></a></div><p><img src="http://themocracy.com/wp-content/uploads/2010/02/json.gif" alt="json with wordpress" title="json-wordpress" width="128" height="128" class="alignright size-full wp-image-259" />With the popularity of jQuery, AJAX, and client-side programming operations in general, there&#8217;s more use made of JSON as a format for getting data backwards and forwards. </p>
<p>For example, the Twitter API offers data as JSON  &#8211; and more manageably than accessing their RSS XML feeds for user timelines etc.</p>
<pre>http://twitter.com/status/user_timeline/USERNAME.json?count=10 </pre>
<p>The issue is how to make use of JSON-encoded information in the WordPress environment &#8211; much of what is available is only recently available, so some care has to be taken about how it&#8217;s used.</p>
<h3>1. Native PHP functions</h3>
<p><strong>json_encode()</strong> and <strong>json_decode()</strong> make life very simple &#8211; but these functions are only available in PHP >= 5.2.0 and WordPress is still designed to run on significantly older versions of PHP than this. Alternatives would have to be supplied if you were thinking about releasing a plugin. There are custom-written functions to reproduce these in PHP4, see for example user contributions to <a href="http://php.net/manual/en/function.json-encode.php">json_encode</a>. These are often not 100% perfect, but one may well do all that you require&#8230;</p>
<h3>2. JSON2</h3>
<p>If you&#8217;re happy to do the work in jQuery/javaScript, WordPress 2.9 comes with JSON2 bundled, registered and ready to go&#8230;</p>
<pre class="brush: php">
add_action(&#039;wp_print_scripts&#039;,&#039;load_json_parser&#039;);

function load_json_parser(){

	if (is_admin()) return; // probably don&#039;t want this on admin pages

	wp_enqueue_script(&#039;json2&#039;);

}
</pre>
<p>No need any more to play around with eval in the javaScript, but again, this is a WordPress >= 2.9 thing&#8230;. </p>
<h3>3. Borrowing the Text Editor</h3>
<p>Lastly, there is one more, slightly unofficial, dodge that can be used. WordPress makes use of TinyMCE as its rich text editor and this comes with the its own JSON parser. Results may not be completely predictable. </p>
<pre class="brush: php">
require_once(ABSPATH.&quot;/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php&quot;);

$jsObj = new Moxiecode_JSON();

// encodes the supplied array to JSON format
$json = $jsObj-&gt;encode(array(&quot;key1&quot;=&gt;&quot;value1&quot;,&quot;key2&quot;=&gt;&quot;value2&quot;));

//decodes supplied JSON to a PHP array
$json_array = $jsObj-&gt;decode($json);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/02/json-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A jQuery Slideshow for WordPress 2.9</title>
		<link>http://themocracy.com/2010/02/jquery-slideshow-wordpress/</link>
		<comments>http://themocracy.com/2010/02/jquery-slideshow-wordpress/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 11:03:46 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[thumbnails]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=248</guid>
		<description><![CDATA[You want a jQuery slideshow for your WordPress blog? - on the front page, or maybe in the sidebar? No real problem, all the javascript is taken of with the help of a jQuery plugin, all we have to do is figure out how to get the post data. 

And to keep things really simple, this is going to use the thumbnail functions in WP 2.9 - no need to mess around with custom fields any more. ]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fjquery-slideshow-wordpress%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fjquery-slideshow-wordpress%2F" height="61" width="51" /></a></div><p><img class="alignright size-medium wp-image-249" title="jquery-slideshow" src="http://themocracy.com/wp-content/uploads/2010/02/jquery-slideshow-300x206.gif" alt="jquery slideshow" width="245" height="168" /><strong>You want a jQuery slideshow for your WordPress blog? </strong>- on the front page, or maybe in the sidebar? No real problem, all the javascript is taken of with the help of a jQuery plugin, all we have to do is figure out how to get the post data.</p>
<p>And to keep things really simple, this is going to use the thumbnail functions in WP 2.9 &#8211; no need to mess around with custom fields any more.<br />
<span id="more-248"></span><br />
Firstly, you do have to explicitly declare the new thumbnail system in <strong>functions.php</strong> &#8211; and best to wrap it up in an &#8220;if function exists&#8221; to avoid problems for older WP installs.</p>
<pre class="brush: php">
if (function_exists(&#039;add_theme_support&#039;)) {
add_theme_support( &#039;post-thumbnails&#039; );
add_image_size(&#039;slideshow-image&#039;, 300, 160); // for front page slideshow
}
</pre>
<p>The smart move is to define a &#8220;Featured&#8221; category &#8211; any post in that category will be available for the slideshow, and that&#8217;s the selection taken care of. Create a category &#8211; call it featured, or anything, but make a note of the cat_ID &#8211; mouseover a category on the admin categories page and it&#8217;ll be in the url, something like:</p>
<blockquote><p>http://testblog.com/wp-admin/categories.php?action=edit&#038;<strong>cat_ID=3</strong></p></blockquote>
<p>The ordering will be by date, newest first. (Don&#8217;t forget you can tweak the timestamp of a post if you really want to just to get the order exactly as you want it).</p>
<p>So create a couple of posts in this category and add some thumbnails to them &#8211; since our slideshow is going to be 300px by 160px, make sure they&#8217;re bigger than that. Then, in <strong>home.php</strong>, or <strong>index.php</strong>, where ever you want the slideshow to appear, add:</p>
<pre class="brush: php">
&lt;?php

$featured_category_id = 3;
$number_of_posts = 4;

$args = array(&#039;showposts&#039;=&gt;$number_of_posts, &#039;cat&#039;=&gt;$featured_category_id);

$slideshow_query = new WP_Query($args);

?&gt;
&lt;div id=&quot;slideshow&quot;&gt;
&lt;?php
// let&#039;s keep a record of the post IDs as we go, in case we want to omit these from other post loops/lists on the same page
$duplicates = array();

while ($slideshow_query-&gt;have_posts()) : $slideshow_query-&gt;the_post();

//add the ID to the duplicates array for future reference
$duplicates[] = $id;

//test to see whether there&#039;s a thumbnail associated with the post
if (has_post_thumbnail()) {
?&gt;
&lt;div class=&quot;post-thumbnail&quot;&gt;
&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;
&lt;?php	the_post_thumbnail(&#039;slideshow-image&#039;); ?&gt;
&lt;/a&gt;
&lt;/div&gt;
&lt;?php	}
endwhile;
?&gt;
&lt;/div&gt;  &lt;!-- end of #slideshow --&gt;
</pre>
<p>Next, some javascript. We can use the excellent <a href="http://malsup.com/jquery/cycle/">jQuery Cycle Plugin</a> &#8211; as the package stands currently, we&#8217;ll use <strong>jquery.cycle.all.min.js</strong> &#8211; which allows all the possible transition effects etc. &#8211; in practice, you may well want to use the lighter versions&#8230;</p>
<p>* For a standard production site, always use <strong>min</strong> = minified,  rather than <strong>pack</strong> = packed &#8211; pack may be a smaller filesize, but it doesn&#8217;t run quicker&#8230;.</p>
<p>We need a very quick script to configure and activate the plugin &#8211; so create a new file, <strong>slideshow-activate.js</strong></p>
<pre class="brush: js">
jQuery(document).ready(function($){
$(&#039;#slideshow&#039;).cycle({
fx: &#039;fade&#039; // choose your transition type, ex: fade, scrollUp, shuffle, etc...
});
});
</pre>
<p>Later, there are lots of options here, transition speed, pausing etc. &#8211; consult the <a href="http://malsup.com/jquery/cycle/browser.html">plugin pages</a> for ideas.</p>
<p>We need to get our scripts on the WordPress page, and indicate that they depend on jQuery being loaded &#8211; making use of the WordPress functions <strong>wp_register_script</strong> and <strong>wp_enqueue_script</strong> &#8211; so in <strong>functions.php</strong></p>
<pre class="brush: php">

add_action(&#039;wp&#039;, &#039;js_head_load&#039;);

function js_head_load(){

if(is_admin()) return;  //so that we&#039;re not loading unecessary scripts in the admin

wp_register_script(&#039;cycle&#039;, get_bloginfo(&#039;template_directory&#039;)  . &#039;/scripts/jquery.cycle.all.min.js&#039;, array(&#039;jquery&#039;), &#039;1.0&#039;);

wp_enqueue_script(&#039;slideshow-activate&#039;,  get_bloginfo(&#039;template_directory&#039;)  . &#039;/scripts/slideshow-activate.js&#039;, array(&#039;jquery&#039;, &#039;cycle&#039;), &#039;1.0&#039;);

}
</pre>
<p>And then, don&#8217;t forget to put the 2 files into /scripts in your theme folder&#8230;</p>
<p>That should give you a working slideshow &#8211; ready to be styled with some CSS. Note that the way the Cycle plugin works is that it looks to rotate the immediate children of the div being called &#8211; here, they&#8217;re images, they could be eg. divs &#8211; so if you add a wrapper div(s) you may need to adjust slideshow-activate.js.</p>
<p>And if it&#8217;s not working, check first that the right scripts (jQuery, Cycle, slideshow-activate) are actually being loaded and in the right order, by looking at the page source &#8211; and check you&#8217;ve got thumbnails attached to the relevant posts&#8230;</p>
<p>You could go on to tidy this up &#8211; avoiding the hard-coded category id by having something in the theme options admin to change the id for example. Also, as said earlier, there&#8217;s a lot of scope in playing with the plugin parameters to get exactly the slideshow you want&#8230;</p>
<p>Lastly &#8211; the record of the duplicates we kept &#8211; the method for omitting them from subsequent Loops of posts is here: <a href="http://themocracy.com/2010/01/multiple-wordpress-queries-duplicates/">Multiple WordPress query duplicates</a></p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/02/jquery-slideshow-wordpress/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using Google Code libraries with WordPress</title>
		<link>http://themocracy.com/2010/02/using-google-code-libraries-with-wordpress/</link>
		<comments>http://themocracy.com/2010/02/using-google-code-libraries-with-wordpress/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 15:54:40 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mootools]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=224</guid>
		<description><![CDATA[By default, WordPress loads the version of jQuery that comes with the package. But there is an alternative way of doing it and that&#8217;s to use the AJAX Libraries API at Google Code &#8211; use their bandwidth, why not&#8230; A few lines added to your functions.php in the theme you&#8217;re building and you&#8217;re ready to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fusing-google-code-libraries-with-wordpress%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F02%2Fusing-google-code-libraries-with-wordpress%2F" height="61" width="51" /></a></div><p><img class="alignright size-full wp-image-207" title="wordpress-250x250" src="http://themocracy.com/wp-content/uploads/2010/01/wordpress-250x250.png" alt="" width="192" height="192" /><strong>By default, WordPress loads the version of jQuery that comes with the package.</strong> But there is an alternative way of doing it and that&#8217;s to use the AJAX Libraries API at Google Code &#8211; use their bandwidth, why not&#8230;</p>
<p>A few lines added to your functions.php in the theme you&#8217;re building and you&#8217;re ready to go.<br />
<span id="more-224"></span><br />
<strong> wp_register_script()</strong> &#8211; the useful point is that you can use this function to access scripts hosted elsewhere&#8230;</p>
<p>Just add this code to your <strong>functions.php</strong> file:</p>
<pre class="brush: php">
add_action(&#039;template_redirect&#039;, &#039;js_head_load&#039;);

function js_head_load(){

if(is_admin()) return;

wp_deregister_script(&#039;jquery&#039;);
wp_register_script(&#039;jquery&#039;, &#039;http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js&#039;);
wp_enqueue_script(&#039;jquery&#039;);
// and then any other scripts to register and queue...
}
</pre>
<p>Notice the first line of the function ensures that the jQuery isn&#8217;t loaded on WP admin pages -<em> if a script isn&#8217;t needed, don&#8217;t load it on the page</em> &#8211; and in this case jQuery in noConflict mode  can cause the admin rich text editor and the widget drag and drop interface to go awry..</p>
<p><strong>The advantages</strong>:-<br />
You&#8217;ll be able to update the version your site is using quickly and easily, probably a good thing.</p>
<p>Google Code tends to have a policy of only including versions demonstrated to be stable, jQuery 1.2.4 and 1.2.5 didn&#8217;t make the grade</p>
<p>The user may already have it cached in their browser via some previously visited site instead of downloading from a location on your site (and if enough sites do it, the chances are that much greater that they will have a copy in the cache).</p>
<p>Not just jQuery &#8211; check out jQuery UI<br />
<a href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js">http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js</a><br />
And MooTools, which seems seriously under-used in conjunction with WordPress<br />
<a href="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js">http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js</a></p>
<p>Always grab the minified version.</p>
<p>And lastly, one disadvantage:- googleapis.com does go down very occasionally &#8211; but then again a site ought to function, more or less, without javaScript.</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/02/using-google-code-libraries-with-wordpress/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WordPress Theme Frameworks</title>
		<link>http://themocracy.com/2010/01/wordpress-theme-frameworks/</link>
		<comments>http://themocracy.com/2010/01/wordpress-theme-frameworks/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 16:18:31 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Themes]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=214</guid>
		<description><![CDATA[Since the arrival of WordPress 2.7, the true framework is based on the concept of parent/child WordPress themes. A child theme is dependent on its parent - here, the framework - for its template files and functions, it's not going work without it.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fwordpress-theme-frameworks%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fwordpress-theme-frameworks%2F" height="61" width="51" /></a></div><p><img class="alignright size-full wp-image-220" title="wordpress-framework" src="http://themocracy.com/wp-content/uploads/2010/01/wordpress-framework.jpg" alt="" width="290" height="169" /><strong>Since the arrival of WordPress 2.7, the true framework is based on the concept of parent/child WordPress themes.</strong></p>
<p>A child theme is dependent on its parent &#8211; here, the framework &#8211; for its template files and functions, it&#8217;s not going work without it &#8211; &#8216;parasite&#8217; might be a better name.</p>
<p>When you install a WordPress framework theme, it doesn&#8217;t look very impressive to start with &#8211; black and white &#8211; but that&#8217;s not the point. The basic idea is to cover all the fundamentals in the parent framework, the stuff every good theme needs, and keep separate the fancy styling, add-ons etc. in the child theme.<br />
<span id="more-214"></span><br />
The art of a good framework is how it lets in the customization. Much like PHP frameworks, used wisely, they allow flexibility and concise code, quickly applied &#8211; used unwisely, they rapidly become a big old mess with far too many moving parts&#8230;</p>
<p>Any good WordPress theme developer will have ended up with a core code that does the job the way he or she thinks best &#8211; and this is the origin of a framework. Frankly, if you are are more programming-orientated as a theme designer than design-orientated, they may not be for you. Whether you stick with your code, or dip into your first framework child theme, up to you&#8230; but here are the current market leaders, as it were, in no particularly significant order.</p>
<p><a href="http://themeshaper.com/thematic/">Thematic</a><br />
<a href="http://themeshaper.com/thematic/"><img class="alignright size-full wp-image-215" title="mw372" src="http://themocracy.com/wp-content/uploads/2010/01/mw372.png" alt="" width="400" height="125" /></a> Produced by Ian Stewart, the prime mover in getting parent-child themes off the ground, Thematic has grids, CSS  frameworks, and 13 different widget-ready areas. There&#8217;s a growing selection of child themes, free and premium, and support forums.</p>
<p><a href="http://themehybrid.com/">ThemeHybrid</a><br />
<a href="http://themehybrid.com/"><img class="alignright size-full wp-image-216" title="ThemeHybrid" src="http://themocracy.com/wp-content/uploads/2010/01/mw373.png" alt="" width="400" height="125" /></a>Again, all the usual goodies, ThemeHybrid also comes with a good selection of child themes built up. For enhanced support in developing and customizing your own theme, ThemeHybrid has a paid club membership option (currently US$25).</p>
<p><a href="http://www.zy.sg/the-buffet-framework/">Buffet</a><br />
<a href="http://www.zy.sg/the-buffet-framework/"><img class="alignright size-full wp-image-217" title="buffet" src="http://themocracy.com/wp-content/uploads/2010/01/mw374.png" alt="" width="400" height="125" /></a>Buffet has a variety of jQuery features &#8211; Superfish menus, SuperSleight for png transparency in IE6, jBreadcrumb.  It also offers 2 CSS frameworks &#8211; 960gs and the Blueprint CSS frameworks &#8211; and support for microformats, XOXO, hAtom, hCard&#8230;</p>
<p><a href="http://www.plaintxt.org/themes/sandbox/">Sandbox</a><br />
<a href="http://www.plaintxt.org/themes/sandbox/"><img class="alignright size-full wp-image-218" title="sandbox" src="http://themocracy.com/wp-content/uploads/2010/01/mw376.png" alt="" width="400" height="125" /></a>Sandbox is probably the original &#8211; been around for years &#8211; a minimalist WordPress Theme, designed for developers to build on and produce workable themes simply using CSS. But it&#8217;s fully widget-ready, XHTML valid and released under the GPL.</p>
<p><a href="http://onepresscommunity.com/">OnePress</a><br />
<a href="http://onepresscommunity.com"><img class="alignright size-full wp-image-219" title="onepress" src="http://themocracy.com/wp-content/uploads/2010/01/mw371.png" alt="" width="400" height="125" /></a>The unique proposition for OnePress is its integration with phpBB, with a unified login and forum messages displayed on the blog &#8211; if you&#8217;re a jobbing site-builder this is certainly something that comes up as a very common client requirement.</p>
<p><strong>Conclusion</strong></p>
<p>There are other frameworks &#8211; many other frameworks &#8211; in different states of development. This is a hot topic in WordPress theme design and I&#8217;m sure the situation will continue to evolve &#8211; much like the arrival of javascript libraries, there&#8217;ll be a fair amount of competition before the winner(s) emerge.</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/01/wordpress-theme-frameworks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JQuery, Cufon and WordPress</title>
		<link>http://themocracy.com/2010/01/jquery-cufon-and-wordpress/</link>
		<comments>http://themocracy.com/2010/01/jquery-cufon-and-wordpress/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 13:48:58 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[cufon]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=209</guid>
		<description><![CDATA[Just at the moment the best font replacement technique around is cufón – so how to get this technique into your WordPress theme design?]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fjquery-cufon-and-wordpress%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fjquery-cufon-and-wordpress%2F" height="61" width="51" /></a></div><p><img class="alignright size-thumbnail wp-image-207" title="wordpress-250x250" src="http://themocracy.com/wp-content/uploads/2010/01/wordpress-250x250-150x150.png" alt="" width="150" height="150" />Just at the moment the best font replacement technique around is <a href="http://wiki.github.com/sorccu/cufon/">cufón</a> &#8211; so how to get this technique into your WordPress theme design?</p>
<p>You&#8217;ll need 3 javascript files &#8211; best to put them in the theme directory under /scripts</p>
<p>1. The Cufon javascript<br />
2. The individual font javascript &#8211; downloaded from cufon &#8211; or use their excellent generator http://cufon.shoqolate.com/generate/  (not all fonts as .ttf will do the trick, there&#8217;s issues of licensing in terms of web embedding)<br />
3. A custom script, very simple, just to activate.<br />
<span id="more-209"></span><br />
The plan is to get the scripts loading in the WP header, and the best action hook for this is <strong>template_redirect</strong> &#8211; so, in <strong>functions.php</strong></p>
<pre class="brush: php">
add_action(&#039;template_redirect&#039;, &#039;them_js_head_load&#039;);

function them_js_head_load(){

define(TH_TEMPLATE_URL, get_bloginfo(&#039;template_url&#039;));

wp_register_script(&#039;cufon&#039;, TH_TEMPLATE_URL . &#039;/scripts/cufon-yui.js&#039;, array(&#039;jquery&#039;), &#039;1.0&#039;);
wp_register_script(&#039;my_font&#039;, TH_TEMPLATE_URL . &#039;/scripts/myfont.font.js&#039;, array(&#039;jquery&#039;), &#039;1.0&#039;);
wp_enqueue_script(&#039;fontsactivate&#039;, TH_TEMPLATE_URL . &#039;/scripts/fontsactivate.js&#039;, array(&#039;jquery&#039;, &#039;cufon&#039;, &#039;them_font&#039;), &#039;1.0&#039;);
}
</pre>
<p><strong>fontsactivate.js</strong> is as simple as you want to make it &#8211; just this, for example, will replace all post h2 headings on the page</p>
<pre class="brush: js">
Cufon.replace(&#039;.post h2&#039;);
</pre>
<p>Don&#8217;t imagine it&#8217;s a great idea to replace all the text on a page with a custom font, that&#8217;ll make the server chug a bit &#8211; stick with headings&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/01/jquery-cufon-and-wordpress/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>More WordPress and jQuery</title>
		<link>http://themocracy.com/2010/01/more-wordpress-and-jquery/</link>
		<comments>http://themocracy.com/2010/01/more-wordpress-and-jquery/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 13:15:57 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=195</guid>
		<description><![CDATA[To refine a previous post on WordPress and jQuery and the use of the wp_enqueue_script function, its paths and dependencies. As a barebones example, this is how we do it when we we&#8217;re enqueueing &#8211; if that&#8217;s a word &#8211; the jQuery Cycle plugin, so that we can make a slideshow on the page. The [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fmore-wordpress-and-jquery%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F01%2Fmore-wordpress-and-jquery%2F" height="61" width="51" /></a></div><p>To refine a previous post on WordPress and jQuery and the use of the <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script">wp_enqueue_script</a> function, its paths and dependencies.</p>
<p>As a barebones example, this is how we do it when we we&#8217;re enqueueing &#8211; if that&#8217;s a word &#8211; the <a href="http://www.malsup.com/jquery/cycle/">jQuery Cycle plugin</a>, so that we can make a slideshow on the page.<br />
<span id="more-195"></span><br />
The important point is probably in the dependencies &#8211; firstly, the Cycle plugin depends on jQuery, so has to be loaded after &#8211; secondly, our custom script to run the whole process on depends on the jQuery Cycle plugin and therefore also on jQuery and is the last to load.</p>
<p>The custom script we&#8217;ve written is in <strong>them_directory/scripts/them.cycle.js</strong>  &#8211; something very simple, like this:-</p>
<pre class="brush: js">
jQuery(document).ready(function($) {

$(&#039;#images&#039;).cycle({
//some parameters
 });
});
</pre>
<p>(Don&#8217;t forget, the dollar $ object isn&#8217;t defined in WordPress jQuery (historical reasons) &#8211; hence the form of the first line) </p>
<p>This is client-display side javascript, as opposed to admin-side, (which tends to follow slightly different rules in the WordPress setup) and in this case, the action hook &#8216;template_redirect&#8217; is usually the time to do it.</p>
<p>To enqueue the jQuery library itself is simple &#8211; it&#8217;s already registered by default in WordPress, no need to specify other than the default path and version.</p>
<p>So in <strong>functions.php</strong> </p>
<pre class="brush: php">
add_action(&#039;template_redirect&#039;, &#039;them_js_head_load&#039;);

function them_js_head_load(){

	//register the plugin
	wp_enqueue_script(&#039;jquery-cycle&#039;, THEM_TEMPLATEURL.&#039;/scripts/jquery.cycle.lite.min.js&#039;, array(&#039;jquery&#039;), &#039;1.0&#039;);
	//register the custom script
	wp_enqueue_script(&#039;them-cycle&#039;, THEM_TEMPLATEURL.&#039;/scripts/them.cycle.js&#039;, array(&#039;jquery&#039;, &#039;jquery-cycle&#039;), &#039;1.0&#039;);

}
</pre>
<p>Note for convenience and efficiency, we&#8217;ve previously defined</p>
<pre class="brush: php">

define(THEM_TEMPLATEURL, get_bloginfo(&#039;template_directory&#039;));
</pre>
<p>And what you end up with in the page source should be something like this &#8211; javascripts loaded in the right place in the page head, up and running</p>
<p><strong>&lt;script type=&#8217;text/javascript&#8217; src=&#8217;http://localhost/test/wp-content/themes/this-theme/scripts/jquery.cycle.lite.min.js?ver=1.0&#8242;&gt;&lt;/script&gt;</strong></p>
<p><strong>&lt;script type=&#8217;text/javascript&#8217; src=&#8217;http://localhost/test/wp-content/themes/this-theme/scripts/them.cycle.js?ver=1.0&#8242;&gt;&lt;/script&gt;</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/01/more-wordpress-and-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using jQuery with WordPress</title>
		<link>http://themocracy.com/2009/04/using-jquery-with-wordpress/</link>
		<comments>http://themocracy.com/2009/04/using-jquery-with-wordpress/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 12:51:04 +0000</pubDate>
		<dc:creator>Lisa</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://localhost/themocracy/?p=3</guid>
		<description><![CDATA[If you&#8217;re a theme developer, you&#8217;ll (perhaps) be looking at keeping up with the latest in javascript/AJAX and incorporating a few tweaks into your brand new theme &#8211; in some ways, it&#8217;s been made very easy for you (and in one or two ways it&#8217;s just a little tricky&#8230;) So, assuming you have a basic [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2009%2F04%2Fusing-jquery-with-wordpress%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2009%2F04%2Fusing-jquery-with-wordpress%2F" height="61" width="51" /></a></div><p><img style="padding:2px;border:2px solid #ccc;margin:0 0 0 10px;" src="http://themocracy.com/wp-content/uploads/2009/04/mw022.png" alt="mw022" title="mw022" width="229" height="75" class="alignright size-full wp-image-6" /><strong>If you&#8217;re a theme developer, you&#8217;ll (perhaps) be looking at keeping up with the latest in javascript/AJAX and incorporating a few tweaks into your brand new theme</strong> &#8211; in some ways, it&#8217;s been made very easy for you (and in one or two ways it&#8217;s just a little tricky&#8230;)<br />
<span id="more-3"></span><br />
So, assuming you have a basic knowledge of PHP, theme design and javascript, here&#8217;s how it works:-</p>
<p><strong>Loading up jQuery</strong></p>
<p>WordPress arrives with jQuery already bundled, so this bit&#8217;s easy enough. But we need to get it loaded onto the page, which doesn&#8217;t happen automatically&#8230;</p>
<p>The plan here would be to get some nice tabbed divisions going, maybe in the sidebar, courtesy of jQuery.</p>
<pre class="brush: php">
&lt;?php
add_action(&#039;template_redirect&#039;, &#039;them_js_head_load&#039;);

function them_js_head_load(){

 // we don&#039;t need this on admin pages, so...
	if(is_admin()) return;

      wp_enqueue_script(&#039;tabber&#039;, get_bloginfo(&#039;template_directory&#039;) . &#039;/scripts/tabs.js&#039;, array(&#039;jquery&#039;, &#039;jquery-ui-core&#039;, &#039;jquery-ui-tabs&#039;), &#039;1.0&#039;);
}
 ?&gt;
</pre>
<p>In this code, we&#8217;ve enqueued a custom script <strong>tabs.js</strong>, that&#8217;s going to initiate the whole process &#8211; and we&#8217;ve also declared its dependencies &#8211; <strong>jquery</strong>, <strong>jquery-ui-core</strong>, <strong>jquery-ui-tabs</strong>, the user interface sublibraries, also bundled into WordPress as standard.</p>
<p>These are already registered, so only the handle is required, here: &#8216;jquery-ui-tabs&#8217;, etc. </p>
<p>The full list of bundled libraries is at: <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script">WordPress wp_enqueue_script</a>.</p>
<p><strong>Vital!</strong> &#8211; The snippets of jQuery code you&#8217;ll find while out and about on the net make extensive use of the shortcut $ to express the jQuery global object. This isn&#8217;t going to work in WordPress, so at all times we use  <strong>jQuery</strong>(document).ready(function($) &#8211; and then it will work&#8230; Once inside the function, we can use $ as a shortcut. </p>
<p>The reason for this slight complication is that Prototype and Scriptaculous libraries arrived first into WordPress and have got to hold on to using the $ shortcut. And don&#8217;t be tempted to dabble with <strong>jQuery.noConflict()</strong> here &#8211; you won&#8217;t get good results.</p>
<p>And from here, since you know what you want to put in your theme in terms of flashy javascript/AJAX add-ons, I&#8217;ll leave you to get on with thieving some snippets and getting them up and running&#8230;.</p>
<p><strong>* Update</strong> &#8211; some of this information is superseded by changes in the way WordPress handles the loading of javascript &#8211; there&#8217;s a follow-up here &#8211; <a href="http://themocracy.com/2010/01/more-wordpress-and-jquery/">More about WordPress and jQuery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2009/04/using-jquery-with-wordpress/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>

