<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>richardsweeney.com</title>
	
	<link>http://richardsweeney.com</link>
	<description>Richard Sweeney</description>
	<lastBuildDate>Wed, 17 Apr 2013 06:35:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/richardsweeneylute" /><feedburner:info uri="richardsweeneylute" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Add a category to media items in WordPress</title>
		<link>http://feedproxy.google.com/~r/richardsweeneylute/~3/p33pDBaY49Y/</link>
		<comments>http://richardsweeney.com/add-a-category-to-media-items-in-wordpress/#comments</comments>
		<pubDate>Fri, 15 Mar 2013 13:47:56 +0000</pubDate>
		<dc:creator>Richard Sweeney</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://richardsweeney.com/?p=527</guid>
		<description><![CDATA[If you want to add categories to images and/or other uploaded files in your WordPress media library (in versions 3.5 and above) it&#8217;s really easy &#8212; once you know how. First register the taxonomy (I&#8217;m just using the built in &#8216;category&#8217; taxonomy type in WordPress, but you could be all fancy and add your own [...]]]></description>
				<content:encoded><![CDATA[<p>If you want to add categories to images and/or other uploaded files in your WordPress media library (in versions 3.5 and<br />
above) it&#8217;s really easy &mdash; once you know how. First register the taxonomy (I&#8217;m just using the built in &#8216;category&#8217; taxonomy type in WordPress, but you could be all fancy and add your own taxonomy if you really want to).</p>
<pre><code>/** Register taxonomy for images */
function olab_register_taxonomy_for_images() {
    register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init', 'olab_register_taxonomy_for_images' );
</code></pre>
<p>Now add the category field to the Media Library table. This will also add a filter to the table to allow search of<br />
attachments by category. Super useful if you&#8217;ve got a bunch of files you need to categorize.</p>
<pre><code> /** Add a category filter to images */
function olab_add_image_category_filter() {
    $screen = get_current_screen();
    if ( 'upload' == $screen-&gt;id ) {
        $dropdown_options = array( 'show_option_all' =&gt; __( 'View all categories', 'olab' ), 'hide_empty' =&gt; false, 'hierarchical' =&gt; true, 'orderby' =&gt; 'name', );
        wp_dropdown_categories( $dropdown_options );
    }
}
add_action( 'restrict_manage_posts', 'olab_add_image_category_filter' );
</code></pre>
<p>Make sure to replace &#8216;olab&#8217; with whatever prefix you&#8217;re using in your theme and/or plugin.</p>
<img src="http://feeds.feedburner.com/~r/richardsweeneylute/~4/p33pDBaY49Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://richardsweeney.com/add-a-category-to-media-items-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://richardsweeney.com/add-a-category-to-media-items-in-wordpress/</feedburner:origLink></item>
		<item>
		<title>Open finder window from terminal in OS X</title>
		<link>http://feedproxy.google.com/~r/richardsweeneylute/~3/JY-EM0CN7lU/</link>
		<comments>http://richardsweeney.com/open-finder-window-from-terminal-in-os-x/#comments</comments>
		<pubDate>Wed, 13 Mar 2013 11:16:02 +0000</pubDate>
		<dc:creator>Richard Sweeney</dc:creator>
				<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://richardsweeney.com/?p=522</guid>
		<description><![CDATA[Here&#8217;s a quick tip. If you&#8217;re hard at work in terminal and want to quickly open a finder window to show the current directory you&#8217;re in just type: $ open . Quick and painless!]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s a quick tip.</p>
<p>If you&#8217;re hard at work in terminal and want to quickly open a finder window to show the current directory you&#8217;re in just type:</p>
<pre><code>$ open .</code></pre>
<p>Quick and painless!</p>
<img src="http://feeds.feedburner.com/~r/richardsweeneylute/~4/JY-EM0CN7lU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://richardsweeney.com/open-finder-window-from-terminal-in-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://richardsweeney.com/open-finder-window-from-terminal-in-os-x/</feedburner:origLink></item>
		<item>
		<title>Simple grids on the fly with Compass</title>
		<link>http://feedproxy.google.com/~r/richardsweeneylute/~3/mBubPao_jXU/</link>
		<comments>http://richardsweeney.com/simple-grids-on-the-fly-with-compass/#comments</comments>
		<pubDate>Sat, 10 Nov 2012 12:11:54 +0000</pubDate>
		<dc:creator>Richard Sweeney</dc:creator>
				<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://richardsweeney.com/?p=491</guid>
		<description><![CDATA[So I made my grid system. It worked great. Then I started building a site in Drupal. It&#8217;s hardly a secret that Drupal&#8217;s markup is really terrible. I have to control my urge to run back screaming to WordPress and never leave again! But such is life. Drupal sure has it strong points and nowadys [...]]]></description>
				<content:encoded><![CDATA[<p>So I made my grid system. It worked great.</p>
<p>Then I started building a site in Drupal.</p>
<p>It&#8217;s hardly a secret that Drupal&#8217;s markup is <em>really</em> terrible. I have to control my urge to run back screaming to WordPress and never leave again! But such is life. Drupal sure has it strong points and nowadys I actually mostly enjoy working with it. Having said that 4,000 divs doesn&#8217;t always make working with the front end so easy, especially if we&#8217;re working with a CSS grid.</p>
<p>So, I wrote a tiny mixin for SASS/Compass that can will work out your grids for you when the markup is against you:</p>
<pre>$columns: 16;
$gridWidth: 960px;
@mixin drupalCols($rows: 4, $padding: 0 10px) {
  width: ($gridWidth / $columns) * $rows;
  float: left;
  padding: $padding;
  @include box-sizing(border-box);
}

.my-div {
  @include drupalCols(8);
}

// This becomes:
/*
.my-div {
  width: 480px;
  float: left;
  padding: 0 10px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
*/

// You can also add more or less padding like this:

.my-div {
  @include drupalCols(4, 10px 20px 30px);
}

/*
.my-div {
  width: 240px;
  float: left;
  padding: 10px 20px 30px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
*/</pre>
<p>This one has fixed pixel values because the project I wrote it for is not responsive and is based on a grid 960px wide divided into 16 sections (yes 16)!</p>
<p>Here&#8217;s one that is responsive based on 12 columns:</p>
<pre>$columns: 12;
$gridWidth: 100%;
@mixin drupalCols($rows: 4, $padding: 0 10px) {
  width: ($gridWidth / $columns) * $rows;
  float: left;
  padding: $padding;
  @include box-sizing(border-box);
}

.my-div {
  @include drupalCols(4);
}

// This becomes:
/*
.my-div {
  width: 33.333%;
  float: left;
  padding: 0 10px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
*/</pre>
<p>For the responsive one to work (if you&#8217;ve got full control of your markup) then you could use this:</p>
<pre>@mixin clearfix {
  &amp;:after {
    content: " ";
    display: table;
    clear: both;
  }
}

$columns: 12;
@while $columns &gt; 0 {
  .span-#{$columns} {
    width: percentage(0.083333 * $columns);
  }
  $columns: $columns - 1;
}

$gutter: 10px;
.row-container {
  margin: $gutter 0;
  @include clearfix;
  &gt; div {
    border-right: $gutter solid transparent;
    border-left: $gutter solid transparent;
    float: left;
    @include clearfix;
    @include box-sizing(border-box);
  }
  &amp;:first-child {
    border-left: none;
  }
  &amp;:last-child {
    border-right: none;
  }
}

//This produces the following:
/*
.span-12 {
  width: 100.0%;
}

.span-11 {
  width: 91.666%;
}

.span-10 {
  width: 83.333%;
}

.span-9 {
  width: 75.0%;
}

.span-8 {
  width: 66.666%;
}

.span-7 {
  width: 58.333%;
}

.span-6 {
  width: 50.0%;
}

.span-5 {
  width: 41.667%;
}

.span-4 {
  width: 33.333%;
}

.span-3 {
  width: 25.0%;
}

.span-2 {
  width: 16.667%;
}

.span-1 {
  width: 8.333%;
}

.row-container {
  margin: 10px 0;
}
.row-container:after {
  content: " ";
  display: table;
  clear: both;
}
.row-container &gt; div {
  border-right: 10px solid transparent;
  border-left: 10px solid transparent;
  float: left;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.row-container &gt; div:after {
  content: " ";
  display: table;
  clear: both;
}
.row-container:first-child {
  border-left: none;
}
.row-container:last-child {
  border-right: none;
}
*/

// Use it like this:
/*
&lt;div&gt;
  &lt;div&gt;
    ...content...
  &lt;/div&gt;
  ...more columns
&lt;/div&gt;
*/</pre>
<p>If you&#8217;re wondering about support for</p>
<pre>box-sizing: border-box;</pre>
<p>be happily surprised: It&#8217;s supported by all major browsers, including IE8! I tend to use it liberally these days in all my projects.</p>
<img src="http://feeds.feedburner.com/~r/richardsweeneylute/~4/mBubPao_jXU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://richardsweeney.com/simple-grids-on-the-fly-with-compass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://richardsweeney.com/simple-grids-on-the-fly-with-compass/</feedburner:origLink></item>
		<item>
		<title>A grid system in SASS/Compass</title>
		<link>http://feedproxy.google.com/~r/richardsweeneylute/~3/VGPlkHXQipY/</link>
		<comments>http://richardsweeney.com/a-grid-system-in-sass/#comments</comments>
		<pubDate>Sat, 03 Nov 2012 20:13:41 +0000</pubDate>
		<dc:creator>Richard Sweeney</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[compass]]></category>
		<category><![CDATA[sass]]></category>

		<guid isPermaLink="false">http://richardsweeney.com/?p=473</guid>
		<description><![CDATA[Update! Check out this post for more refined ideas + some practical considerations when working with &#8216;certain&#8217; CMSs. Driving home this evening I was inspired to write my own CSS grid system. I HATE the idea of bloated CSS frameworks. I&#8217;ve never been able to bring myself to use one, despite the obvious advantages. I [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Update! </strong>Check out <a title="Simple grids on the fly with Compass" href="http://richardsweeney.com/simple-grids-on-the-fly-with-compass/">this post</a> for more refined ideas + some practical considerations when working with &#8216;certain&#8217; CMSs.</p>
<p>Driving home this evening I was inspired to write my own CSS grid system. I HATE the idea of bloated CSS frameworks. I&#8217;ve never been able to bring myself to use one, despite the obvious advantages. I do, however love SASS and particularly Compass (wait, isn&#8217;t that a framework already..?!).</p>
<p>The solution is simple: write my own. I haven&#8217;t really started yet, but the basic setup took around 10 seconds using SASS and I just had to share it!</p>
<pre>.row-container {
  width: 100%;
  &gt; div {
    float: left;
  }
}

$columns: 12;

@while $columns &gt; 0 {
  .span-#{$columns} {
    width: percentage((1 / 12) * $columns);
  }
  $columns: $columns - 1;
}</pre>
<p>which magically becomes:</p>
<pre>.row-container {
  width: 100%;
}

.row-container &gt; div {
  float: left
}

.span-12 {
  width: 100%;
}

.span-11 {
  width: 91.667%;
}

.span-10 {
  width: 83.333%;
}

.span-9 {
  width: 75%;
}

.span-8 {
  width: 66.667%;
}

.span-7 {
  width: 58.333%;
}

.span-6 {
  width: 50%;
}

.span-5 {
  width: 41.667%;
}

.span-4 {
  width: 33.333%;
}

.span-3 {
  width: 25%;
}

.span-2 {
  width: 16.667%;
}

.span-1 {
  width: 8.333%;
}</pre>
<p>With an HTML structure like:</p>
<pre>&lt;div class="row-container"&gt;
  &lt;div class="span-4"&gt;
    &lt;p&gt;Stuff&lt;/p&gt;
  &lt;/div&gt;
  ...
&lt;/div&gt;</pre>
<p>Not bad for 10 seconds work! Let&#8217;s see how long it takes to build something (responsive) that can actually be used for production stuff. Fun, fun, fun :)</p>
<img src="http://feeds.feedburner.com/~r/richardsweeneylute/~4/VGPlkHXQipY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://richardsweeney.com/a-grid-system-in-sass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://richardsweeney.com/a-grid-system-in-sass/</feedburner:origLink></item>
		<item>
		<title>10 course lute by Klaus Jacobsen for sale!</title>
		<link>http://feedproxy.google.com/~r/richardsweeneylute/~3/hGm9HSY-GkU/</link>
		<comments>http://richardsweeney.com/10-course-lute-by-klaus-jacobsen-for-sale/#comments</comments>
		<pubDate>Sun, 21 Oct 2012 11:36:24 +0000</pubDate>
		<dc:creator>Richard Sweeney</dc:creator>
				<category><![CDATA[music]]></category>

		<guid isPermaLink="false">http://richardsweeney.com/?p=450</guid>
		<description><![CDATA[I&#8217;m selling my 10 course lute, built in 2005. The lute comes with a Kingham case. Both the lute and case are in excellent condition. I&#8217;m looking for 30.000SEK / £3000 or thereabouts. Don&#8217;t hesitate to get in touch if you&#8217;re interested or if have any questions about the instrument.]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m selling my 10 course lute, built in 2005. The lute comes with a Kingham case. Both the lute and case are in excellent condition.</p>
<p>I&#8217;m looking for 30.000SEK / £3000 or thereabouts. Don&#8217;t hesitate to <a href="http://richardsweeney.com/contact/">get in touch</a> if you&#8217;re interested or if have any questions about the instrument.</p>
<p><img class="alignnone size-large wp-image-451" title="10 course lute, Klaus Jacobsen, 2005" src="http://richardsweeney.com/wp-content/uploads/IMG_6384-1024x764.jpg" alt="" /></p>
<p><img class="alignnone size-large wp-image-453" title="10 course lute by Klaus Jacobsen, 2005" src="http://richardsweeney.com/wp-content/uploads/IMG_63851-764x1024.jpg" alt="" /></p>
<p><img class="alignnone size-large wp-image-454" title="10 course lute by Klaus Jacobsen, 2005" src="http://richardsweeney.com/wp-content/uploads/IMG_6386-1024x764.jpg" alt="" /></p>
<img src="http://feeds.feedburner.com/~r/richardsweeneylute/~4/hGm9HSY-GkU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://richardsweeney.com/10-course-lute-by-klaus-jacobsen-for-sale/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://richardsweeney.com/10-course-lute-by-klaus-jacobsen-for-sale/</feedburner:origLink></item>
		<item>
		<title>5 course baroque guitar by Ivo Magherini for sale</title>
		<link>http://feedproxy.google.com/~r/richardsweeneylute/~3/HiMsSbgRDqQ/</link>
		<comments>http://richardsweeney.com/5-course-baroque-guitar-by-ivo-magherini-for-sale/#comments</comments>
		<pubDate>Sun, 21 Oct 2012 09:49:06 +0000</pubDate>
		<dc:creator>Richard Sweeney</dc:creator>
				<category><![CDATA[music]]></category>

		<guid isPermaLink="false">http://richardsweeney.com/?p=463</guid>
		<description><![CDATA[Update: The guitar has now been sold! I&#8217;m selling my guitar built by Ivo in 2006. Ivo is probably most well known for his guitars and this is a great instrument that has served me well in the opera pit and concert hall for many years! Due to it&#8217;s life as a working instrument the [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Update: The guitar has now been sold!</strong></p>
<p>I&#8217;m selling my guitar built by Ivo in 2006. Ivo is probably most well known for his guitars and this is a great instrument that has served me well in the opera pit and concert hall for many years!</p>
<p>Due to it&#8217;s life as a working instrument the guitar has a bit of wear-and-tear on the soundboard but is otherwise in good condition. Comes with a Kingham case (in good condition).</p>
<p>I&#8217;m looking for 22.500 SEK / £2200 for the instrument. Don&#8217;t hesitate to <a href="http://richardsweeney.com/contact/">get in touch</a> with any questions you might have.</p>
<p><img src="http://richardsweeney.com/wp-content/uploads/IMG_6610-768x1024.jpg" alt="" title="5 course baroque guitar by Ivo Magherini" class="alignnone size-large wp-image-465" /></p>
<p><img src="http://richardsweeney.com/wp-content/uploads/bild-4-500x375.jpg" alt="" title="Baroque guitar, Ivo Magherini" class="alignnone size-medium wp-image-468" /></p>
<p><img src="http://richardsweeney.com/wp-content/uploads/bild-5-500x375.jpg" alt="" title="Baroque guitar, Ivo Magherini" class="alignnone size-medium wp-image-469" /></p>
<img src="http://feeds.feedburner.com/~r/richardsweeneylute/~4/HiMsSbgRDqQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://richardsweeney.com/5-course-baroque-guitar-by-ivo-magherini-for-sale/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://richardsweeney.com/5-course-baroque-guitar-by-ivo-magherini-for-sale/</feedburner:origLink></item>
		<item>
		<title>ConcertPress released to WordPress plugin repository!</title>
		<link>http://feedproxy.google.com/~r/richardsweeneylute/~3/SdIuGX0JGOM/</link>
		<comments>http://richardsweeney.com/concertpress-released-to-wordpress-plugin-repository/#comments</comments>
		<pubDate>Thu, 16 Aug 2012 07:50:50 +0000</pubDate>
		<dc:creator>Richard Sweeney</dc:creator>
				<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://richardsweeney.com/?p=444</guid>
		<description><![CDATA[Well, it finally happened: I&#8217;ve released ConcertPress to the WP plugin repository. It&#8217;s been a long time coming and was just a matter of finding the time to fix those last few bugs and dare to release it into the wild! ConcertPress is an events management plugin specifically designed for classical musicians. It&#8217;s largely inspired [...]]]></description>
				<content:encoded><![CDATA[<p>Well, it finally happened: I&#8217;ve released ConcertPress to the WP plugin repository. It&#8217;s been a long time coming and was just a matter of finding the time to fix those last few bugs and dare to release it into the wild!</p>
<p>ConcertPress is an events management plugin specifically designed for classical musicians. It&#8217;s largely inspired by the excellent <a href="http://gigpress.com/">GigPress</a> which I used for a few years. GigPress is fab for most musos and the main difference between it and ConcertPress is the ability to add programmes and programme details.</p>
<p>ConcertPress can be downloaded via the WordPress <a href="http://wordpress.org/extend/plugins/concertpress/">plugin repository</a> or via <a href="https://github.com/richardsweeney/concertPress">github</a>.</p>
<img src="http://feeds.feedburner.com/~r/richardsweeneylute/~4/SdIuGX0JGOM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://richardsweeney.com/concertpress-released-to-wordpress-plugin-repository/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://richardsweeney.com/concertpress-released-to-wordpress-plugin-repository/</feedburner:origLink></item>
		<item>
		<title>Welcome to richardsweeney.com v4.0!</title>
		<link>http://feedproxy.google.com/~r/richardsweeneylute/~3/ZWpmzQGUjnA/</link>
		<comments>http://richardsweeney.com/welcome-to-richardsweeney-com-v4-0/#comments</comments>
		<pubDate>Tue, 14 Aug 2012 09:51:12 +0000</pubDate>
		<dc:creator>Richard Sweeney</dc:creator>
				<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://richardsweeney.com/?p=387</guid>
		<description><![CDATA[A warm welcome to the fourth incarnation of my website and blog. The site is (finally) now fully responsive (the previous incarnation was my very first attempt at responsive design) and the theme design is (obviously) my own. For those of you don&#8217;t know what &#8216;responsive&#8217; means: the website adjusts to different screen sizes, reflowing [...]]]></description>
				<content:encoded><![CDATA[<p>A warm welcome to the fourth incarnation of my website and blog. The site is (finally) now fully responsive (the previous incarnation was my very first attempt at responsive design) and the theme design is (obviously) my own. For those of you don&#8217;t know what &#8216;responsive&#8217; means: the website adjusts to different screen sizes, reflowing content layout as required for better readability.</p>
<p>My goal this time round was (as well as creating a responsive site) to not use any WordPress or JavaScript plugins. This time I wanted to build <em>everything</em> myself. I&#8217;m delighted to say that I managed it all except for the plugin I use for server-side caching, which is not my area of expertise. <a href="http://wordpress.org/extend/plugins/wp-super-cache/">WP Super Cache</a> is such an excellent solution and so very easy to implement, so I used that.</p>
<p>So, <strong>what did I do then?!</strong></p>
<p>Well, I build the <strong>contact form</strong> on the <a title="contact" href="http://richardsweeney.com/contact/">contact page</a>. The form uses JavaScript validation (my own) and is submitted via AJAX. I used Akismet for spam protection on the server-side and a honey-pot* as an extra anti-spam measure. Works great.</p>
<p>I also wrote my own <strong>comment form</strong> script (see below this post!), which again uses Akismet for spam checking and simple JavaScript validation. Comments are submitted via AJAX.</p>
<p>Speaking of AJAX&#8230; I also wrote a <strong>custom pagination</strong> solution for my <a title="blog" href="http://richardsweeney.com/blog/">blog</a> in AJAX. I used the HTML5 history API to push changes in page to the URL so all pages will have proper, linkable URLs. I freely admit here that I used Benjamin Lupton&#8217;s <a href="https://github.com/balupton/History.js/">History.js</a> to sort out all the rough edges of different browser implementations of the API!</p>
<p>Also on the <a title="blog" href="http://richardsweeney.com/blog/">blog page</a> I use a custom <strong>excerpt</strong> function that&#8217;s a bit more versatile than WordPress&#8217; built in <code>the_excerpt()</code>.</p>
<p>I also wrote my own script in jQuery to fetch my <strong>Instagram feed</strong> (check out the right-sidebar/below this post). Fetched results from the Instagram API are cached in localStorage (where available) for speedy subsequent page visits. For good measure I also wrote the <strong>lightbox script</strong> used to enlarge the images. The <strong>twitter feed</strong> is also written in jQuery and all scripts are loaded asynchronously so that page load is not blocked.</p>
<p>That&#8217;s about it! It&#8217;s a great feeling to have such control over the entire contents &amp; markup of a website. I ♥ WordPress.</p>
<p><em>*An input field in the form that is hidden from visitors via CSS. As it&#8217;s hidden, user&#8217;s won&#8217;t fill it out, but if form fields are filled out automatically (ie by a spam bot), it will help to show up spam.</em></p>
<img src="http://feeds.feedburner.com/~r/richardsweeneylute/~4/ZWpmzQGUjnA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://richardsweeney.com/welcome-to-richardsweeney-com-v4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://richardsweeney.com/welcome-to-richardsweeney-com-v4-0/</feedburner:origLink></item>
		<item>
		<title>WordPress: create a widget using code from a plugin class</title>
		<link>http://feedproxy.google.com/~r/richardsweeneylute/~3/ogCFbmBNBoU/</link>
		<comments>http://richardsweeney.com/wordpress-create-a-widget-using-code-from-a-plugin-class/#comments</comments>
		<pubDate>Tue, 03 Jul 2012 12:47:41 +0000</pubDate>
		<dc:creator>Richard Sweeney</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://richardsweeney.com/?p=372</guid>
		<description><![CDATA[I&#8217;m writing a new WordPress plugin: an audio player written atop the marvellous jPlayer. I wanted to give the user the option to add the audio player via a widget, but as my plugin was written OOP I wasn&#8217;t really sure how to register the widget using code from my plugin. It turns out it [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m writing a new WordPress plugin: an audio player written atop the marvellous <a href="http://jplayer.org/">jPlayer</a>. I wanted to give the user the option to add the audio player via a widget, but as my plugin was written OOP I wasn&#8217;t really sure how to register the widget using code from my plugin.</p>
<p>It turns out it wasn&#8217;t particularly difficult, but I couldn&#8217;t find any documentation about it online, so I figured I&#8217;d write this wee post, in the hope that it might come in useful for my fellow WordPressers!</p>
<p>My plugin code is written in OOP:</p>
<pre>class MyCoolPlugin {
// All my methods + properties here
}
// Instantiate the class
$cool_plugin = new MyCoolPlugin();</pre>
<p>The class contains a method to create the HTML that I want to use for both a shortcode and a widget.</p>
<pre>class MyCoolPlugin {
  // Returns the HTML for a shortcode or widget
  function shortcode_widget() {
    return '&lt;p&gt;HTML rocks&lt;/p&gt;';
  }
}
// Instantiate the class
$cool_plugin = new MyCoolPlugin();</pre>
<p>Register my widget:</p>
<pre>class CoolWidget extends WP_Widget {
  function CoolWidget() {
    // Instantiate the parent object
    parent::__construct( false, 'Cool Widget' );
  }
}</pre>
<p>Then I can add the HTML from the shorcode_widget method of MyCoolClass like so:</p>
<pre>class CoolWidget extends WP_Widget {
  function CoolWidget() {
    // Instantiate the parent object
    parent::__construct( false, 'Cool Widget' );
  }
  function widget($args, $instance) {
    // reuse my plugin's code
    global $cool_plugin;
    echo $cool_plugin-&gt;shortcode_widget();
  }
}</pre>
<p>Nice. Saves me writing a bunch of code multiple times, which I guess is the main point of OOP!</p>
<img src="http://feeds.feedburner.com/~r/richardsweeneylute/~4/ogCFbmBNBoU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://richardsweeney.com/wordpress-create-a-widget-using-code-from-a-plugin-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://richardsweeney.com/wordpress-create-a-widget-using-code-from-a-plugin-class/</feedburner:origLink></item>
		<item>
		<title>JavaScript: how to select the first word(s) in a sentence</title>
		<link>http://feedproxy.google.com/~r/richardsweeneylute/~3/mZxRJerHd0E/</link>
		<comments>http://richardsweeney.com/javascript-how-to-select-the-first-words-in-a-sentence/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 13:44:21 +0000</pubDate>
		<dc:creator>Richard Sweeney</dc:creator>
				<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://richardsweeney.com/?p=350</guid>
		<description><![CDATA[Recently I had to figure out a way to select the first 2 words in a sentence using JavaScript. I wanted to wrap them in a class so that I could give them some additional CSS styling. I figured it&#8217;d be mad easy, but it took a little bit of head scratching until I figured [...]]]></description>
				<content:encoded><![CDATA[<p>Recently I had to figure out a way to select the first 2 words in a sentence using JavaScript. I wanted to wrap them in a class so that I could give them some additional CSS styling. I figured it&#8217;d be mad easy, but it took a little bit of head scratching until I figured out at least one way to do it.</p>
<p>I&#8217;ve got an HTML element with an ID of &#8216;niceText&#8217; that I&#8217;m looking to grab. I&#8217;ll save the string as a variable called &#8216;niceText&#8217;.</p>
<pre>var niceText = $('#niceText').text();</pre>
<p>I&#8217;ll also save the opening and closing spans I&#8217;m going to wrap the text in as variables like so:</p>
<pre>var openSpan = '&lt;span class="grey"&gt;<span class="grey"><span class="grey">', closeSpan = '&lt;/span&gt;</span></span>';</pre>
<p>Next, we&#8217;ll use the native JavaScript <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/split">split method</a>. This makes an array out of a string &#8211; all you have to do is to specify the separator that&#8217;ll be used to divide the string. In this case the separator is a blank space, so we can write:</p>
<pre>niceText = niceText.split(' ');</pre>
<p>Our variable &#8216;niceText&#8217; is now an array of strings (go ahead and use your console to take a peek at what&#8217;s happened to our variable).</p>
<p>Next we&#8217;ll add the span to the start of the array using the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift">unshift method</a>. It you&#8217;ve ever used the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push">push method</a>, this is very similar except that it adds elements to the beginning of the array instead of to the end.</p>
<pre>niceText.unshift( openSpan );</pre>
<p>Fab. We now need to add the closing span to the array. We can do this with the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice">splice method</a>. If you&#8217;re not sure how this method works, do have a good read of the docs as it can come in super handy when performing array surgery!</p>
<p>As I want to wrap the first 2 words in my sentence, I&#8217;m going to add the closing span as the 4th item in the array. The first item is now my opening span, then comes the two opening words, then my closing span. The second value in splice indicates how many values, if any, to remove from the array. We&#8217;re not removing any, just adding, so this will be equal to 0.</p>
<pre>niceText.splice( 3, 0, closeSpan );</pre>
<p>Next I&#8217;ll turn the array back into a string using <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/join">join</a>. Like split, join accepts a value for the separator, only this time, the separator is what will be printed between every array item. As this is just a sentence, we want to add a space between the words, so we can write:</p>
<pre>niceText = niceText.join(' ');</pre>
<p>Finally I&#8217;ll add the string to my HTML element like so:</p>
<pre>$('#niceText').html( niceText );</pre>
<p>That&#8217;s it! Here&#8217;s the whole function.</p>
<pre>jQuery( function($){

   /* Get the text of the element I'm after */
   var niceText = $('#niceText').text(),
      openSpan = '&lt;span class="grey"&gt;<span class="grey">', closeSpan = '&lt;/span&gt;</span>';

   /* Make the sentence into an array */
   niceText = niceText.split(' ');

   /* Add span to the beginning of the array */
   niceText.unshift( openSpan );

   /* Add  as the 4th value in the array */
   niceText.splice( 3, 0, closeSpan );					

   /* Turn it back into a string */
   niceText = niceText.join(' ');					

   /* Append the new HTML to the header */
   $('#niceText').html( niceText );

});</pre>
<p>If you&#8217;re not already using jQuery in your site, it might be a bit much to add it for just this tiny function! Rather, you can simply replace</p>
<pre>var niceText = $('#niceText').text();</pre>
<p>with</p>
<pre>var niceText = document.getElementById('niceText').textContent;</pre>
<p>and</p>
<pre>$('#niceText').html( niceText );</pre>
<p>with</p>
<pre>document.getElementById('niceText').innerHTML = niceText;</pre>
<p>Grand stuff. Hope it comes in useful!</p>
<img src="http://feeds.feedburner.com/~r/richardsweeneylute/~4/mZxRJerHd0E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://richardsweeney.com/javascript-how-to-select-the-first-words-in-a-sentence/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://richardsweeney.com/javascript-how-to-select-the-first-words-in-a-sentence/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.240 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-04-17 20:30:10 --><!-- Compression = gzip -->
