<?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>Gary&#039;s Code</title>
	<atom:link href="http://code.garyjones.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.garyjones.co.uk</link>
	<description>A store for the bits of code I&#039;m always forgetting...</description>
	<lastBuildDate>Tue, 31 Jan 2012 01:47:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Thesis Custom Box + Sidebars to Genesis Split Sidebars</title>
		<link>http://code.garyjones.co.uk/thesis-custom-box-sidebars-to-genesis-split-sidebars/</link>
		<comments>http://code.garyjones.co.uk/thesis-custom-box-sidebars-to-genesis-split-sidebars/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 13:52:44 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Genesis]]></category>
		<category><![CDATA[Thesis]]></category>

		<guid isPermaLink="false">http://code.garyjones.co.uk/?p=2051</guid>
		<description><![CDATA[Visually split the primary sidebar in Genesis into two further sidebars, each with their own widget area. PHP View the code on Gist. CSS View the code on Gist. The Result]]></description>
			<content:encoded><![CDATA[<p>Visually split the primary sidebar in <a href="http://genesis-theme-framework.com/">Genesis</a> into two further sidebars, each with their own widget area.</p>
<p><span id="more-2051"></span></p>
<h2>PHP</h2>
<script src="https://gist.github.com/1698319.js?file=functions.php"></script><noscript><p><a href="https://gist.github.com/1698319">View the code on Gist</a>.</p></noscript>
<h2>CSS</h2>
<script src="https://gist.github.com/1698319.js?file=style.css"></script><noscript><p><a href="https://gist.github.com/1698319">View the code on Gist</a>.</p></noscript>
<h2>The Result</h2>
<p><a href="http://code.garyjones.co.uk/thesis-custom-box-sidebars-to-genesis-split-sidebars/split-sidebars/" rel="attachment wp-att-2053"><img src="http://code.garyjones.co.uk/files/split-sidebars.png" alt="" title="Split Sidebars" width="500" height="502" class="aligncenter size-full wp-image-2053" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://code.garyjones.co.uk/thesis-custom-box-sidebars-to-genesis-split-sidebars/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTTP Error FixCan now upload large images</title>
		<link>http://code.garyjones.co.uk/http-error-fix/</link>
		<comments>http://code.garyjones.co.uk/http-error-fix/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 17:16:43 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://code.garyjones.co.uk/?p=2049</guid>
		<description><![CDATA[When uploading large images over an approximate size (~2500&#215;2000) I was encountering the HTTP Error message when trying to crunch the image (which ultimately fails and doesn&#8217;t produce the smaller pre-defined image sizes). After trying several solutions, the following appears to have solved it for my setup, once and for all &#8211; add this to [...]]]></description>
			<content:encoded><![CDATA[<p>When uploading large images over an approximate size (~2500&#215;2000) I was encountering the <code style="color: red;font-weight:bold">HTTP Error</code> message when trying to crunch the image (which ultimately fails and doesn&#8217;t produce the smaller pre-defined image sizes).</p>
<p>After trying several solutions, the following appears to have solved it for my setup, once and for all &#8211; add this to your <code>.htaccess</code> file:</p>
<p><span id="more-2049"></span></p>
<script src="https://gist.github.com/1698353.js"></script><noscript><p><a href="https://gist.github.com/1698353">View the code on Gist</a>.</p></noscript>
<p>In short, it massively bumps up the allowed memory limit, and also tries to turn off some security aspects for the file that deals with the uploading, under different module setups.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.garyjones.co.uk/http-error-fix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Style Sheet Header ImprovementsTidy up your WordPress Theme Details</title>
		<link>http://code.garyjones.co.uk/style-sheet-header-improvements/</link>
		<comments>http://code.garyjones.co.uk/style-sheet-header-improvements/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 00:14:25 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://code.garyjones.co.uk/?p=2046</guid>
		<description><![CDATA[The Theme Review Guidelines are often updated as each new version of WordPress is released, and although these guidelines are for themes submitted to the WordPress theme repository, they are a good baseline to which all themes should strive to achieve. If your theme was written a while ago, your site might not be following [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://codex.wordpress.org/Theme_Review">Theme Review Guidelines</a> are often updated as each new version of WordPress is released, and although these guidelines are for themes submitted to the <a href="http://wordpress.org/extend/themes/">WordPress theme repository</a>, they are a good baseline to which all themes should strive to achieve.</p>
<p>If your theme was written a while ago, your site might not be following all of the current best practices. Here are a few simple alterations you can make to your <code>style.css</code> file.</p>
<p><span id="more-2046"></span><br />
<h2 id="theme-uri">Theme URI</h2>
<p>An easy one to start &#8211; in the header info, you&#8217;ll likely find a line starting with <code>Theme URL</code> (note the last character). This should now strictly be <code>Theme URI</code>.</p>
<h2 id="license">License</h2>
<p>In your theme, you might see some inconsistent or no license information at all. There are now a couple of specific slugs you can use, <code>License</code> and <code>License URI</code>, to show the same information in a way that WordPress can read from (example):</p>
<script src="https://gist.github.com/1698383.js"></script><noscript><p><a href="https://gist.github.com/1698383">View the code on Gist</a>.</p></noscript>
<h2 id="tags">Tags</h2>
<p>Tags haven&#8217;t been added to many themes at the moment, yet if you&#8217;ve got a lot of themes installed, being able to filter them to just certain features (see Appearance -> Themes -> Feature Filter, right-hand side, next to the Search button) could be useful. Many of the tags could be added by the functionality that a parent theme like <a href="http://genesis-theme-framework.com/">Genesis</a> provides, while some would be child theme specific. A theme that could theoretically meet every single tag would include the following:</p>
<script src="https://gist.github.com/1698372.js"></script><noscript><p><a href="https://gist.github.com/1698372">View the code on Gist</a>.</p></noscript>
<h2 id="trailing-slash">Trailing Slash</h2>
<p>Another easy one &#8211; if the <code>Theme URI</code> or <code>Author URI</code> values are the home page of a website, add a trailing slash to it &#8211; this typically saves an extra lookup on a server if someone clicks on the link.</p>
<h2 id="theme-name">Theme Name</h2>
<p>Some themes might be named as &#8220;&#8230; Theme&#8221; or &#8220;&#8230; Child Theme&#8221;. The Theme Review guidelines recommend that the term &#8220;Theme&#8221; is not included (as everyone knows it&#8217;s a theme). Since the guidelines also suggest that the fact a theme is a child theme be mentioned in the <code>Description</code>, your theme could drop both terms. <strong>Switch to another theme before changing your theme name.</strong></p>
<h2 id="template-version">Template Version</h2>
<p>Previously there was a suggestion to include a <code>Template Version</code> slug to child themes to indicate what version of the parent theme the child theme was built against. However, this appears to have been removed until such time that WordPress can actually use this information to notify users.</p>
<h2 id="further-information">Further Information</h2>
<p>Beyond the changes listed above, you can find more information via the <a href="http://codex.wordpress.org/Theme_Review">theme review guidelines</a>, by following the <a href="http://make.wordpress.org/themes">Theme Review Team</a> discussions, and also by running the <a href="http://wordpress.org/extend/plugins/theme-check/">Theme Check</a> plugin (the development version has a few extra fixes) on your theme. WordPress also has a set of <a href="http://codex.wordpress.org/CSS_Coding_Standards">CSS Coding Standards</a> for the main portion of yout style sheet.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.garyjones.co.uk/style-sheet-header-improvements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Remove Title Attributes on Genesis Menus</title>
		<link>http://code.garyjones.co.uk/remove-genesis-navigation-titles/</link>
		<comments>http://code.garyjones.co.uk/remove-genesis-navigation-titles/#comments</comments>
		<pubDate>Sat, 28 May 2011 09:48:37 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Genesis]]></category>

		<guid isPermaLink="false">http://code.garyjones.co.uk/?p=2027</guid>
		<description><![CDATA[Genesis 1.6 has removed the menus that this tutorial applies to, in favour of using native WordPress custom menus, but they can be added back in via Nick&#8216;s Genesis Nav Menu Amplified plugin. If you&#8217;re using the Genesis-created menus from the Theme Settings page, you don&#8217;t have as much control or flexibility as using custom [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Genesis 1.6 has removed the menus that this tutorial applies to, in favour of using native WordPress custom menus, but they can be added back in via <a href="http://designsbynickthegeek.com">Nick</a>&#8216;s <a href="http://wordpress.org/extend/plugins/genesis-nav-menu-amplified/">Genesis Nav Menu Amplified</a> plugin.</strong></p>
<p>If you&#8217;re using the Genesis-created menus from the Theme Settings page, you don&#8217;t have as much control or flexibility as using <a href="http://dev.studiopress.com/custom-nav-menus.htm" title="Dev.SP: How to Use Custom Nav Menus">custom menus</a>. You may not want to switch to custom menus, just to remove the title attributes, say, so we need a different solution.<br />
<span id="more-2027"></span></p>
<h2 id="title-attributes">What Are Title Attributes?</h2>
<div id="attachment_2028" class="wp-caption aligncenter" style="width: 426px"><img src="http://code.garyjones.co.uk/files/title-tooltip.png" alt="Demonstration of a title tooltip" title="Demonstration of a title tooltip" width="416" height="77" class="size-full wp-image-2028" /><p class="wp-caption-text">Demonstration of a title tooltip</p></div>
<p>The title attribute is most often seen appearing as tooltips when you hover over one of the menu items. With custom menus, you can edit the title attribute to what you want, or even remove it altogether, but with the Genesis-created menus, it&#8217;s automatically populated, and there&#8217;s no interface for removing them.</p>
<p>However, we can remove them with some code.<br />
<p>Open up the <code>functions.php</code> file in your child theme and add the following code. The code should be entered at the end of the file, just before the closing <code>?></code> if there is one.</p></p>
<script src="https://gist.github.com/1698416.js"></script><noscript><p><a href="https://gist.github.com/1698416">View the code on Gist</a>.</p></noscript>
<p>That looks through all of the navigation list items (Pages or Categories) for <code> title="&#x2026;"</code> and removes them, before returning the list items markup to the function that creates Genesis menus.</p>
<h2 id="being-selective">Being Selective</h2>
<p>What would you do if you just want to remove the title attributes on either the primary or secondary navigation, rather than both? Some slight changes are needed:</p>
<script src="https://gist.github.com/1698437.js"></script><noscript><p><a href="https://gist.github.com/1698437">View the code on Gist</a>.</p></noscript>
<p>That would remove all the attributes for Pages or Categories menu in the Primary Menu slot. You can make it specific to just the Secondary Menu slot by amending all occurrences of <code>primary</code> to be <code>secondary</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.garyjones.co.uk/remove-genesis-navigation-titles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install WordPress via SSH</title>
		<link>http://code.garyjones.co.uk/install-wordpress-ssh/</link>
		<comments>http://code.garyjones.co.uk/install-wordpress-ssh/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 11:32:57 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://code.garyjones.co.uk/?p=2008</guid>
		<description><![CDATA[SSH into your server, then navigate to your domain&#8217;s web root: cd /var/www/vhosts/example.com/httpdocs Grab the latest WP install wget http://wordpress.org/latest.tar.gz Get the files out of the archive: tar xfz latest.tar.gz Navigate to the wordpress subfolder: cd wordpress Copy everything back up to the web root: cp -rpf * ../ Navigate back up to web root: [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li><abbr title="Secure shell">SSH</abbr> into your server, then navigate to your domain&#8217;s web root:<br />
<kbd>cd <var>/var/www/vhosts/example.com/httpdocs</var></kbd></li>
<li>Grab the latest <abbr title="WordPress">WP</abbr> install<br />
<kbd>wget http://wordpress.org/latest.tar.gz</kbd></li>
<li>Get the files out of the archive:<br />
<kbd>tar xfz latest.tar.gz</kbd></li>
<li>Navigate to the <code>wordpress</code> subfolder:<br />
<kbd>cd wordpress</kbd></li>
<li>Copy everything back up to the web root:<br />
<kbd>cp -rpf * ../</kbd></li>
<li>Navigate back up to web root:<br />
<kbd>cd ..</kbd></li>
<li>Remove the <code>wordpress</code> subfolder:<br />
<kbd>rm -rf wordpress</kbd></li>
<li>Remove the downloaded archive file:<br />
<kbd>rm -f latest.tar.gz</kbd></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://code.garyjones.co.uk/install-wordpress-ssh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Conditionally Add Style Sheets for IE in WordPress</title>
		<link>http://code.garyjones.co.uk/ie-conditional-style-sheets-wordpress/</link>
		<comments>http://code.garyjones.co.uk/ie-conditional-style-sheets-wordpress/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 16:39:32 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://code.garyjones.co.uk/?p=2026</guid>
		<description><![CDATA[Over time, Internet Explorer (IE) is getting better at rendering web pages how we want them, but while IE7 and earlier versions still have a (fast-fading) grip, we sometimes still need to provide exclusive styles to make them render our sites in an acceptable way. That is where conditional style sheets are used. View the [...]]]></description>
			<content:encoded><![CDATA[<p>Over time, Internet Explorer (IE) <em>is</em> getting better at rendering web pages how we want them, but while IE7 and earlier versions still have a (fast-fading) grip, we sometimes still need to provide exclusive styles to make them render our sites in an acceptable way. That is where <em>conditional style sheets</em> are used.<br />
<span id="more-2026"></span> <p>Open up the <code>functions.php</code> file in your child theme and add the following code. The code should be entered at the end of the file, just before the closing <code>?></code> if there is one.</p></p>
<script src="https://gist.github.com/1698719.js"></script><noscript><p><a href="https://gist.github.com/1698719">View the code on Gist</a>.</p></noscript>
<p>The first function enqueues a reference to a style sheet file called <code>style-ie7.css</code> in our child theme folder. Using the <code>wp_enqueue_style()</code> is the correct way of adding style sheet references, as amongst other reasons, it provides a <em>handle</em> that we end up using in the second function. We hook the function in with a priority of <code>200</code>. This make sure it appears after any other style sheets that you or a plugin have added in.</p>
<p>The second function surrounds what will be the <code>&lt;link></code> markup with a <a href="http://www.quirksmode.org/css/condcom.html" title="See more examples of conditional comments" target="_blank">conditional comment</a> to target only browsers that are less than or equal to (the <code>lte</code> bit) IE7. Other conditional comments are available, but this is by far the most common approach, with IE6- and IE7-specific styles thrown into the same file, to avoid an extra <abbr>HTTP</abbr> request. Browsers which aren&#8217;t IE just see the output as one big comment and promptly ignore it.</p>
<p>Credit to <a href="http://wordpress.mfields.org/">Michael Fields</a> for highlighting the <code>script_loader_tag</code> filter methodology to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.garyjones.co.uk/ie-conditional-style-sheets-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Correctly Add a Tweet Button</title>
		<link>http://code.garyjones.co.uk/add-tweet-button/</link>
		<comments>http://code.garyjones.co.uk/add-tweet-button/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 14:00:14 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://code.garyjones.co.uk/?p=2029</guid>
		<description><![CDATA[The end result from a different Genesis article on How to Add a Tweet Button on Single Posts can also be implemented in an advanced way across all themes, which avoids the need to use invalid markup as suggested by Twitter. While being substantially more code, this has several advantages: If JavaScript isn&#8217;t enabled, the [...]]]></description>
			<content:encoded><![CDATA[<p>The end result from a different <a href="http://genesis-theme-framework.com/">Genesis</a> article on <a href="http://dev.studiopress.com/add-tweet-button.htm" title="Dev.SP: How to Add a Tweet Button on Single Posts">How to Add a Tweet Button on Single Posts</a> can also be implemented in an advanced way across all themes, which avoids the need to use invalid markup as suggested by Twitter.<br />
<p>Open up the <code>functions.php</code> file in your child theme and add the following code. The code should be entered at the end of the file, just before the closing <code>?></code> if there is one.</p></p>
<pre class="brush: php; title: ; notranslate">add_action( 'wp_print_scripts', 'child_add_tweet_button' );
/**
 * Add tweet link and script.
 *
 * @author Gary Jones
 * @link http://code.garyjones.co.uk/add-tweet-button/
 */
function child_add_tweet_button() {

	// Only add this to anything not a page
	if ( ! is_page() ) {

		// Add a script to the bottom of the source
		wp_enqueue_script( 'tweet-button', 'http://platform.twitter.com/widgets.js', array(), '', true );

		// Filter in the required Twitter link for limited and unlimited content
		add_filter( 'the_content', 'child_add_tweet_button_link' );
		add_filter( 'the_content_limit', 'child_add_tweet_button_link' );

		// Remove stripped link from excerpts.
		add_filter( 'wp_trim_excerpt', 'child_remove_stripped_tweet_button' );

		// Optionally add it in to excerpts properly (uncomment to use).
		//add_filter( 'the_excerpt', 'child_add_tweet_button_link' );
	}
}

/**
 * Add tweet link.
 *
 * @author Gary Jones
 * @link http://code.garyjones.co.uk/add-tweet-button/
 *
 * @param string $content HTML markup for post content
 * @return string HTML markup for post content
 */
function child_add_tweet_button_link( $content ) {
	global $post;

	$query_string_parameters = array(

		// URL of the page to share
		'url' =&gt; get_permalink(),

		// Screen name of the user to attribute the Tweet to
		'via' =&gt; 'GaryJ',

		// Default Tweet text - here, the post title
		'text' =&gt; get_the_title( $post-&gt;ID ),

		// Related accounts that will be suggested to follow once tweet has been shared
		'related' =&gt; '',

		// Count box position - 'horizontal', 'vertical' or 'none'
		'count' =&gt; 'vertical',

		// The language for the Tweet Button - default is English (en)
		'lang' =&gt; 'en',

		// The URL to which your shared URL resolves to
		'counturl' =&gt; get_permalink()
	);

	// Optionally use this if you have custom shortlinks set up. Uncomment to use.
	//$query_string_parameters['url'] = wp_get_shortlink();

	// Construct our URL to pass to Twitter - gets urlencoded here
	$twitter_url = add_query_arg( $query_string_parameters, '//twitter.com/share' );

	return '&lt;a href=&quot;' . htmlspecialchars( $twitter_url ) . '&quot; class=&quot;twitter-share-button&quot;&gt;Tweet&lt;/a&gt;' . $content;
}

/**
 * Excerpt strip HTML, so the Tweet link just ends up as &quot;Tweet&quot; prefixed to the first word of the excerpt.
 *
 * Does mean that you can't start any article with the word Tweet, but this is an edge scenario.
 *
 * @author Gary Jones
 * @link http://code.garyjones.co.uk/add-tweet-button/
 *
 * @param string $content Plain text
 * @return string
 */
function child_remove_stripped_tweet_button( $content ) {
	return preg_replace( '/^Tweet/', '', $content, 1 );
}</pre>
<p>While being substantially more code, this has several advantages:</p>
<ul>
<li>If JavaScript isn&#8217;t enabled, the markup is still valid for the default Genesis doctype; <code>data-*</code> attributes are only valid in <abbr title="hypertext markup language">HTML</abbr>5, and while most users will have this switched out of the <abbr title="document object model">DOM</abbr> in favour of the added iframe, the markup added by the first method is invalid for <abbr title="extensible hypertext markup language">XHTML</a> 1.0 Strict.</li>
<li>The JavaScript from Twitter is only added once, at the bottom of the page, and not every time the button appears, such as on archive pages.</li>
<li>The &#8220;text&#8221; argument is explicitely given as the title of the post in which the button appears (and not the title of the page where the post appears), meaning you can add buttons to posts on archive pages, or featured posts widget posts, and have the correct text be used.</li>
<li>You can easily and optionally enable the button for excerpts as well as limited and unlimited post content.</li>
<li>You can easily and optionally have your post shortlink as the URL to share, instead of the full permalink. Good if you&#8217;re tracking traffic through the shortlink.</li>
<li>There are no redundant &#8220;Tweet&#8221; strings added at the beginning of excerpts, where the markup has been stripped.</li>
<li>There is support for the &#8220;related&#8221; and &#8220;lang&#8221; arguments, allowing easier customization.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://code.garyjones.co.uk/add-tweet-button/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Genesis Grid Loop Advanced</title>
		<link>http://code.garyjones.co.uk/genesis-grid-loop-advanced/</link>
		<comments>http://code.garyjones.co.uk/genesis-grid-loop-advanced/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 19:58:16 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Genesis]]></category>

		<guid isPermaLink="false">http://code.garyjones.co.uk/?p=1998</guid>
		<description><![CDATA[While the simple example of how to use the Genesis grid loop might be enough to get you up and running, there are far more advanced ways you can use the grid loop to really get the best out of it. This tutorial will go through the steps to adding a variable column balanced grid [...]]]></description>
			<content:encoded><![CDATA[<p>While the simple example of <a href="http://dev.studiopress.com/genesis-grid-loop.htm" title="Dev.SP: How to Use the Genesis Grid Loop">how to use the Genesis grid loop</a> might be enough to get you up and running, there are far more advanced ways you can use the grid loop to really get the best out of it.</p>
<p>This tutorial will go through the steps to adding a variable column balanced grid for any archive page on your site. If you just want the code, <a href="#final" title="Putting It Altogether">skip to the final section</a>. All of the code snippets go at the end of your child theme <code>functions.php</code> file, just before any closing <code>?></code> there might be, except for the <abbr title="Cascading style sheets">CSS</abbr> which will go at the end of your child theme <code>style.css</code> (or <code>css/custom.css</code> for <a href="http://gmj.to/prose" title="Prose Child Theme">Prose</a>) file.</p>
<p><strong>This tutorial requires Genesis 1.5 or later to work.</strong> Adding it to a child theme while running an earlier version of Genesis will kill your site, so go ahead and update Genesis first!<br />
<span id="more-1998"></span></p>
<h2 id="using">Using A Grid Loop</h2>
<p>The first thing we need to decide, is on which pages we want the grid loop to run. The simple example tells you to put the loop helper function straight into <code>home.php</code>, which means it won&#8217;t run on category, tag, monthly, or other archive pages.</p>
<pre class="brush: php; title: ; notranslate">add_action( 'genesis_before_loop', 'child_maybe_do_grid_loop' );
/**
 * Before we get to the loop, see if we're anywhere but a single page. If so,
 * swap out the standard loop for our grid loop.
 *
 * @author Gary Jones
 * @link http://dev.studiopress.com/genesis-grid-loop-advanced.htm
 */
function child_maybe_do_grid_loop() {

	// Amend this conditional to pick where this grid looping occurs
	if ( ! is_single() &amp;&amp; ! is_page() ) {

		// Remove the standard loop
		remove_action( 'genesis_loop', 'genesis_do_loop' );

		// Use the prepared grid loop
		add_action( 'genesis_loop', 'child_do_grid_loop' );

		// Add some extra post classes to the grid loop so we can style the columns
		add_filter( 'genesis_grid_loop_post_class', 'child_grid_loop_post_class' );
	}
}</pre>
<p>This function uses the <a href="http://codex.wordpress.org/Conditional_Tags">conditional tag</a> of <code>is_single()</code>, preceded by the negation operator (<code>!</code>) to ensure the grid loop is not used on single posts, custom post types or attachments, and <code>is_page()</code> preceded by the negation operator to ensure it is not used on Pages either. That leaves it free to be used everywhere else.</p>
<p>The next three lines of code are quite logical &#8211; we remove our normal loop and add in our grid loop, which we&#8217;ll define in a moment. We also make reference to a filter that will add a few <abbr>CSS</abbr> classes which we use to style the columns.</p>
<h2 id="preparing">Preparing The Grid Loop</h2>
<p>Now we need to set up our grid loop. The <code>genesis_grid_loop()</code> functions takes an array of values, which we can configure.</p>
<pre class="brush: php; title: ; notranslate">/**
 * Prepare the grid loop.
 *
 * Takes care of existing query arguments for the page e.g. if it's a category
 * archive page, then the &quot;cat&quot; argument is carried into the grid loop, unless
 * it's overwritten in the $grid_args.
 *
 * @author Gary Jones
 * @link http://dev.studiopress.com/genesis-grid-loop-advanced.htm
 * @uses genesis_grid_loop() Requires Genesis 1.5
 */
function child_do_grid_loop() {

	global $query_string, $paged;

	// Ensure the arguments for the normal query for the page are carried forwards
	parse_str( $query_string, $query_args );

	// Create an array of arguments for the loop - can be grid-specific, or
	// normal query_posts() arguments to alter the loop
	$grid_args = array(
		'features' =&gt; 1,
		'feature_image_size' =&gt; 0,
		'feature_image_class' =&gt; 'alignleft post-image',
		'feature_content_limit' =&gt; 0,
		'grid_image_size' =&gt; 'grid-thumbnail',
		'grid_image_class' =&gt; 'alignleft post-image',
		'grid_content_limit' =&gt; 0,
		'more' =&gt; __( 'Continue reading &amp;#x2192;', 'genesis' ),
		'posts_per_page' =&gt; 6
	);

	// Make sure the first page has a balanced grid
	if ( 0 == $paged )
		// If first page, add number of features to grid posts, so balance is maintained
		$grid_args['posts_per_page'] += $grid_args['features'];
	else
		// Keep the offset maintained from our page 1 adjustment
		$grid_args['offset'] = ( $paged - 1 ) * $grid_args['posts_per_page'] + $grid_args['features'];

	// Merge the standard query for this page, and our preferred loop arguments
	genesis_grid_loop( array_merge( $query_args, $grid_args ) );

}</pre>
<p>There&#8217;s a lot there, so lets go through it. Firstly, we pull in a couple of global values that WordPress has created and populated for us. We need these later in the function, so we need to be able to access the values of them.</p>
<p>Next we take the normal query arguments for that page (like the category ID, tag ID, custom post type name or something else that defines what set of posts we want) and put them into an array. The simple example didn&#8217;t need to include this, as the home page was just showing all posts, in the default date order. Now we&#8217;ve enabled the grid loop on other archive pages, this is needed.</p>
<p>Then comes the main configurable section for how we want the grid loop to run. See the <a href="http://dev.studiopress.com/genesis-grid-loop.htm#parameters">Understanding the Parameters</a> section on the simple example to know what they all mean. The only changes made here, are the number of <code>features</code>, number of <code>posts_per_page</code>, and the <code>more</code> link text.</p>
<p>The bit after that about balancing needs a little bit of explaining. In the simple example, the number of features was equal to the number of columns, meaning that on page 2 and later of the archives, the grid was always complete (except maybe for the final page). However, we want something more flexible that allows, say, 3 columns, and 1 feature post. If we set our <code>posts_per_page</code> to be an exact multiple of the number of columns, then on page 2 and later, the grid is balanced, but page 1, where one of the posts is a feature, means we&#8217;ll have an unsightly gap at the end of the grid. If we increased the <code>posts_per_page</code> so the page 1 looked right, then there would be one extra grid post on it&#8217;s own on all later pages!</p>
<p>What we do, therefore, is adjust the total number of posts to also include the number of feature posts we want, just for page 1 (props to <a href="http://dev.studiopress.com/developers/jen-baumann" title="Jen Baumann - Featured Developer" class="broken_link">Jen</a> for identifying this issue and coming up with a simple fix). Unfortunately, this causes an overlap where the last post(s) (equal to the number of feature posts) on page 1 are repeated at the start of page 2, so we add an offset in, and WordPress starts pulling posts from the database at the right spot. Phew!</p>
<p>Finally, we take the first array of query values, merge it with our provided grid loop values, and send it all off to Genesis to create the grid loop itself. One alternative you might want here is to only show the features and grids on the first page of the archive, and go back to normal posts on page 2 and later. If so, switch the final line:</p>
<pre class="brush: php; title: ; notranslate">// Merge the standard query for this page, and our preferred loop arguments
genesis_grid_loop( array_merge( $query_args, $grid_args ) );</pre>
<p>for:</p>
<pre class="brush: php; title: ; notranslate">// Only use the grid on the first page
if ( 0 == $paged) {
	// Merge the standard query for this page, and our preferred loop arguments
	genesis_grid_loop( array_merge( $query_args, $grid_args ) );
} else {
	query_posts( array_merge( $query_args, $grid_args ) );
	genesis_standard_loop();
}</pre>
<h2 id="styling">Styling The Grid Loop</h2>
<p>In terms of styling, the simple example focused on the case when you have two columns &#8211; float one left, float one right, give them both a width of just under half, with some padding in between. However, if we want more than two columns in our grid, we can&#8217;t make use of the even and odd class names, so we&#8217;ll add our own, using the function we defined earlier on.</p>
<pre class="brush: php; title: ; notranslate">/**
 * Add some extra body classes to grid posts.
 *
 * Change the $columns value to alter how many columns wide the grid uses.
 *
 * @author Gary Jones
 * @link http://dev.studiopress.com/genesis-grid-loop-advanced.htm
 *
 * @global array $_genesis_loop_args
 * @global integer $loop_counter
 * @param array $classes
 */
function child_grid_loop_post_class( $grid_classes ) {
	global $_genesis_loop_args, $loop_counter;

	// Alter this number to change the number of columns - used to add class names
	$columns = 3;

	// Only want extra classes on grid posts, not feature posts
	if ( $loop_counter &gt;= $_genesis_loop_args['features'] ) {

		// Add genesis-grid-column-? class to know how many columns across we are
		$grid_classes[] = sprintf( 'genesis-grid-column-%s', ( ( $loop_counter - $_genesis_loop_args['features'] ) % $columns ) + 1 );

		// Add size1of? class to make it correct width
		$grid_classes[] = sprintf( 'size1of%s', $columns );
	}
	return $grid_classes;
}</pre>
<p>By the time this function is run, we&#8217;re inside the grid loop, about to start showing individual posts. Specifically, this is run when it comes to adding classes to each post.</p>
<p>We start by pulling in another couple of global variables &#8211; one created by Genesis when it was creating the loop, and another from WordPress that identifies how far through the loop we&#8217;ve got; for each post that is displayed, <code>$loop_counter</code> gets increased by one.</p>
<p>The next line is so simple, yet is probably my favourite &#8211; once the CSS is set up (we&#8217;ll get to that shortly), it&#8217;s just this value you need to change to alter between two, three, four or more columns on the grid. Beautiful <img src='http://code.garyjones.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>We then come to adding our extra classes. As we only want them on our grid posts, we skip over this section if we&#8217;re outputting a feature post. For grid posts, there are two classes being added. The first adds a numbered class, indicating which column we&#8217;re in; this allows you to style all of the third column posts, say, via <code>.genesis-grid-column-3 { color: red; }</code>. The second class adds a <code>size1of3</code> class (when <code>$columns</code> = 3), and this is used to specify the width of the column.</p>
<h4>Suggested CSS</h4>
<p>Taking our lead from some of the Genesis 1.5 style sheet styles, we come up with the following:</p>
<pre class="brush: css; title: ; notranslate">#content .genesis-grid {
	float: left;
	margin: 0;
	padding: 15px 0 10px 3%;
}
#content .genesis-grid-column-1 {
	clear:left;
	padding-left: 0;
}
.size1of2 {
    width: 48%;
}
.size1of3 {
    width: 31%;
}
.size1of4 {
    width: 22.5%;
}
.size1of5 {
    width: 17.4%;
}
.size1of6 {
    width: 14%;
}
/* Above widths assume 0 left padding on the first column, 3% left padding on all
subsequent columns, and a total sum of 99% to avoid browser rounding errors */</pre>
<p>All of the grid elements are floated left and have some padding added. The grid posts in the first column are set to stop floating, and move on to a fresh new row, with the left padding removed. Finally, all the column widths are added (for up to 6 columns) based on work that <a href="http://dev.studiopress.com/developers/brian-gardner" title="Brian Gardner">Brian</a> has done on the new Genesis style sheet.</p>
<p>If you want different amounts of padding, then you&#8217;ll need to adjust the <code>width</code> percentages, else you&#8217;ll either have noticeable gaps, or the last post in a row wrapping around to below the others in the same row.</p>
<h2 id="final">Putting it Altogether</h2>
<p>Here&#8217;s the final PHP code to drop in to your <code>functions.php</code> file (and don&#8217;t forget to put the CSS above into your <code>style.css</code>) &#8211; remember to change values on the highlighted lines:</p>
<pre class="brush: php; highlight: [46,47,48,49,50,51,52,53,54,86]; title: ; notranslate">add_action( 'genesis_before_loop', 'child_maybe_do_grid_loop' );
/**
 * Before we get to the loop, see if we're anywhere but a single page. If so,
 * swap out the standard loop for our grid loop.
 *
 * @author Gary Jones
 * @link http://dev.studiopress.com/genesis-grid-loop-advanced.htm
 */
function child_maybe_do_grid_loop() {

	// Amend this conditional to pick where this grid looping occurs
	if ( ! is_single() &amp;&amp; ! is_page() ) {

		// Remove the standard loop
		remove_action( 'genesis_loop', 'genesis_do_loop' );

		// Use the prepared grid loop
		add_action( 'genesis_loop', 'child_do_grid_loop' );

		// Add some extra post classes to the grid loop so we can style the columns
		add_filter( 'genesis_grid_loop_post_class', 'child_grid_loop_post_class' );
	}
}

/**
 * Prepare the grid loop.
 *
 * Takes care of existing query arguments for the page e.g. if it's a category
 * archive page, then the &quot;cat&quot; argument is carried into the grid loop, unless
 * it's overwritten in the $grid_args.
 *
 * @author Gary Jones
 * @link http://dev.studiopress.com/genesis-grid-loop-advanced.htm
 * @uses genesis_grid_loop() Requires Genesis 1.5
 */
function child_do_grid_loop() {

	global $query_string, $paged;

	// Ensure the arguments for the normal query for the page are carried forwards
	parse_str( $query_string, $query_args );

	// Create an array of arguments for the loop - can be grid-specific, or
	// normal query_posts() arguments to alter the loop
	$grid_args = array(
		'features' =&gt; 1,
		'feature_image_size' =&gt; 0,
		'feature_image_class' =&gt; 'alignleft post-image',
		'feature_content_limit' =&gt; 0,
		'grid_image_size' =&gt; 'grid-thumbnail',
		'grid_image_class' =&gt; 'alignleft post-image',
		'grid_content_limit' =&gt; 0,
		'more' =&gt; __( 'Continue reading &amp;#x2192;', 'genesis' ),
		'posts_per_page' =&gt; 6
	);

	// Make sure the first page has a balanced grid
	if ( 0 == $paged )
		// If first page, add number of features to grid posts, so balance is maintained
		$grid_args['posts_per_page'] += $grid_args['features'];
	else
		// Keep the offset maintained from our page 1 adjustment
		$grid_args['offset'] = ( $paged - 1 ) * $grid_args['posts_per_page'] + $grid_args['features'];

	// Merge the standard query for this page, and our preferred loop arguments
	genesis_grid_loop( array_merge( $query_args, $grid_args ) );

}

/**
 * Add some extra body classes to grid posts.
 *
 * Change the $columns value to alter how many columns wide the grid uses.
 *
 * @author Gary Jones
 * @link http://dev.studiopress.com/genesis-grid-loop-advanced.htm
 *
 * @global array $_genesis_loop_args
 * @global integer $loop_counter
 * @param array $classes
 */
function child_grid_loop_post_class( $grid_classes ) {
	global $_genesis_loop_args, $loop_counter;

	// Alter this number to change the number of columns - used to add class names
	$columns = 3;

	// Only want extra classes on grid posts, not feature posts
	if ( $loop_counter &gt;= $_genesis_loop_args['features'] ) {

		// Add genesis-grid-column-? class to know how many columns across we are
		$grid_classes[] = sprintf( 'genesis-grid-column-%s', ( ( $loop_counter - $_genesis_loop_args['features'] ) % $columns ) + 1 );

		// Add size1of? class to make it correct width
		$grid_classes[] = sprintf( 'size1of%s', $columns );
	}
	return $grid_classes;
}</pre>
<h2>Summary</h2>
<p>Even after all of this, there are still more ways you can go extend grid loops &#8211; the code above can be adapted so that you have differently configured grid loops running on different archive pages, or using a grid loop that uses a custom loop to output the posts in some special way (think images + post title caption for a portfolio). Go ahead and experiment!</p>
]]></content:encoded>
			<wfw:commentRss>http://code.garyjones.co.uk/genesis-grid-loop-advanced/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Class for Greatest Common Factor</title>
		<link>http://code.garyjones.co.uk/greatest-common-factor-class/</link>
		<comments>http://code.garyjones.co.uk/greatest-common-factor-class/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 10:53:48 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://code.garyjones.co.uk/?p=1997</guid>
		<description><![CDATA[The following class can be used to find the greatest common factor for two or more numbers by using Euclid&#8217;s algorithm. It was created from original code at http://www.calculatorsoup.com/calculators/math/gcf.php. The Code Usage Extending As the class has protected properties and methods, this class can be extended if you want to, for instance, amend the error [...]]]></description>
			<content:encoded><![CDATA[<p>The following class can be used to find the greatest common factor for two or more numbers by using Euclid&#8217;s algorithm. It was created from original code at <a href="http://www.calculatorsoup.com/calculators/math/gcf.php">http://www.calculatorsoup.com/calculators/math/gcf.php</a>.</p>
<p><span id="more-1997"></span><br />
<h2>The Code</h2>
<pre class="brush: php; title: ; notranslate">&lt;?php
/**
 * @package GCF
 * @author Gary Jones &amp; http://www.calculatorsoup.com/calculators/math/gcf.php
 */

/**
 * GCF is a class for finding the greatest common factor of 2 or more numbers.
 *
 * Requires PHP5.
 */
class GCF {

	/**
	 * Holds all values from which to find the GCF.
	 *
	 * @var array
	 */
	protected $values = array();
	/**
	 * Holds calculated GCF. Initialised to 1.
	 *
	 * @var integer
	 */
	protected $gcf = 1;

	/**
	 * Initialise object - grab values into array, check they are valid, and
	 * if all is well, do the calculation.
	 *
	 * @param integer|array $arg Accepts either an array of integers, or multiple
	 * integer arguments
	 */
	public function __construct( $arg ) {

		// Check for values listed as individual arguments, and grab as array
		if ( func_num_args() &gt; 1 )
			$this-&gt;values = func_get_args();
		else
			$this-&gt;values = (array) $arg;

		// Check we have at least two values
		if ( count( $this-&gt;values ) &lt; 2 ) {
			$this-&gt;error_not_enough_values();
		}

		// Loop through each value to check it is valid
		foreach ( $this-&gt;values as $value ) {
			if ( ! $this-&gt;isValid( $value ) ) {
				$this-&gt;error_invalid_value( $value );
			}
		}

		// Ensure we're at the start of the array
		reset($this-&gt;values);

		// Do the calculation
		$this-&gt;calculate();
	}

	/**
	 * Deal with the case when we only have one value.
	 */
	protected function error_not_enough_values() {
		trigger_error('Not enough values submitted to find the greatest common factor.', E_USER_ERROR);
	}

	/**
	 * Deal with the case when at least one value is invalid.
	 *
	 * @param mixed $value Invalid value that was given
	 */
	protected function error_invalid_value( $value ) {
		trigger_error('The value of ' . $value . ' is invalid for finding the greatest common factor.', E_USER_ERROR);
	}

	/**
	 * Return or echo the calculated GCF value.
	 *
	 * @param boolean $display Whether to echo or return the GCF value. Default is false (return)
	 * @return type
	 */
	public function gcf( $display = false ) {
		if ( $display )
			echo $this-&gt;gcf;
		else
			return $this-&gt;gcf;
	}

	/**
	 * Check each number submitted is valid - not 0 or negative.
	 */
	protected function isValid( $value ) {
		if ( is_int( $value ) &amp;&amp; $value &gt; 0 )
			return true;
		return false;
	}

	/**
	 * Do the calculation of the GCF.
	 */
	protected function calculate() {

		// Count the number of values in the array
		$num_values = count( $this-&gt;values );

		// Get the first 2 values in the array
		$x = current( $this-&gt;values );
		$y = next( $this-&gt;values );

		// set up a for-loop to check through all of the values in the array
		// the first pass will check 2 numbers then each additional pass will check 1
		// make ($num_values - 1) passes
		for ( $i = 1; $i &lt; $num_values; $i++ ) {

			// Set up the larger and smaller of the values
			$a = max( $x, $y );
			$b = min( $x, $y );
			$c = 1;

			// Find the GCF of $a and $b
			// It will be found when $c == 0
			do {
				$c = $a % $b;

				// Capture last value of $b as the potential last GCF result
				$this-&gt;gcf = $b;

				// If $c did not = 0 we need to repeat with the values held in $b and $c
				// at this point $b is higher than $c so we set up for the next iteration
				// set $a to the higher number and $b to the lower number
				$a = $b;
				$b = $c;
			} while ( $c != 0 );

			// If $c == 0 then we have found the GCF of 2 numbers
			// now set up to find the GCF of the last GCF we found and the next value in the array()
			$x = $this-&gt;gcf;
			$y = next( $this-&gt;values );
		}

	}

}</pre>
<h2>Usage</h2>
<pre class="brush: php; title: ; notranslate">// Use an array
$gcf = new GCF( array(225, 45, 15, 540) );
echo 'GCF = ' . $gcf-&gt;gcf();
// Outputs: GCF = 15

// Use a comma-separated list of numbers
$gcf = new GCF( 225, 45, 15, 540 );
echo 'GCF = ' . $gcf-&gt;gcf();
// Outputs: GCF = 15</pre>
<h2>Extending</h2>
<p>As the class has protected properties and methods, this class can be extended if you want to, for instance, amend the error handling for particular objects.</p>
<pre class="brush: php; title: ; notranslate">class My_GCF extends GCF {
	protected function error_invalid_value( $value ) {
		die( $value . ' is not valid.' );
	}
}

$gcf = new My_GCF( array(225, 45, 15, -10) );
echo 'GCF = ' . $gcf-&gt;gcf();
// Outputs: -10 is not valid.</pre>
]]></content:encoded>
			<wfw:commentRss>http://code.garyjones.co.uk/greatest-common-factor-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modify Genesis Breadcrumb Home Link</title>
		<link>http://code.garyjones.co.uk/modify-genesis-breadcrumb-home-link/</link>
		<comments>http://code.garyjones.co.uk/modify-genesis-breadcrumb-home-link/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 14:49:35 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Genesis]]></category>

		<guid isPermaLink="false">http://code.garyjones.co.uk/?p=2023</guid>
		<description><![CDATA[Although there are other ways you can modify the breadcrumb display in Genesis, one thing not covered is being able to change the URL of the Home breadcrumb when it&#8217;s linked. By default, it will point to your home page, which is either a page full of blog posts or a static page, depending on [...]]]></description>
			<content:encoded><![CDATA[<p>Although there are other ways you can <a href="http://code.garyjones.co.uk/modify-breadcrumb-display/" title="Dev.SP: How to Modify the breadcrumb Display">modify the breadcrumb display</a> in <a href="http://genesis-theme-framework.com/">Genesis</a>, one thing not covered is being able to change the <abbr title="uniform resource locator">URL</abbr> of the Home breadcrumb when it&#8217;s linked. By default, it will point to your home page, which is either a page full of blog posts or a static page, depending on what you have set. Changing it is quite simple.<br />
<span id="more-2023"></span><br />
<p>Open up the <code>functions.php</code> file in your child theme and add the following code. The code should be entered at the end of the file, just before the closing <code>?></code> if there is one.</p></p>
<script src="https://gist.github.com/1707605.js"></script><noscript><p><a href="https://gist.github.com/1707605">View the code on Gist</a>.</p></noscript>
<p>We simply search the home breadcrumb for a <code>href</code> attribute and value, and replace it with our new <abbr>URL</abbr>; for this example, it&#8217;s <samp>http://example.com/home</samp> but you&#8217;ll want to change it to something else.<br />
At the time of writing, Genesis 1.5 is in beta, and the same modification can be made, but just on a differently named filter, so that&#8217;s included as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.garyjones.co.uk/modify-genesis-breadcrumb-home-link/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

