<?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>ClarkLab &#187; WordPress</title>
	<atom:link href="http://clarklab.com/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://clarklab.com</link>
	<description>I try to make things that are awesome</description>
	<lastBuildDate>Thu, 02 Feb 2012 07:51:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>Change the default avatar in WordPress</title>
		<link>http://clarklab.com/quick-tip/change-the-default-avatar-in-wordpress/</link>
		<comments>http://clarklab.com/quick-tip/change-the-default-avatar-in-wordpress/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 07:45:48 +0000</pubDate>
		<dc:creator>clark</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[avatar]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://clarklab.com/?p=586</guid>
		<description><![CDATA[If you&#8217;ve ever wanted to change the default avatar in WordPress, all you need is a quick filter in functions.php that inserts and names your new avatar. Once you add the markup below, you&#8217;ll see your new avatar type listed in wp-admin &#62; Settings &#62; Discussion along with the choices like Identicons and MonsterID. The [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever wanted to change the default avatar in WordPress, all you need is a quick filter in functions.php that inserts and names your new avatar. Once you add the markup below, you&#8217;ll see your new avatar type listed in <em>wp-admin &gt; Settings &gt; Discussion</em> along with the choices like Identicons and MonsterID. The code:</p>
<pre name="code" class="php">&lt;?php 
add_filter( 'avatar_defaults', 'newavatar' );  
function newavatar ($avatar_defaults) {  
$myavatar = get_bloginfo('template_directory') . '/images/avatar.png';  
$avatar_defaults[$myavatar] = "Pigs";  
return $avatar_defaults; } ?&gt;</pre>
<p>This is a pretty simple one. Our function newavatar() is hooked to the avatar_defaults, and we simply add our new avatar choice, which includes a path to the image URL along with a title (pigs!). At the end, we <em>return</em> the defaults, which has been impregnated with our new custom avatar, and no one is ever the wiser!</p>
]]></content:encoded>
			<wfw:commentRss>http://clarklab.com/quick-tip/change-the-default-avatar-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress comment hacks: User-only comments, restrict by user age and more</title>
		<link>http://clarklab.com/posts/wordpress-comment-hacks-user-only-comments-restrict-by-user-age-and-more/</link>
		<comments>http://clarklab.com/posts/wordpress-comment-hacks-user-only-comments-restrict-by-user-age-and-more/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 03:43:56 +0000</pubDate>
		<dc:creator>clark</dc:creator>
				<category><![CDATA[posts]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[user meta]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://clarklab.com/?p=550</guid>
		<description><![CDATA[In a recent promo for Android and Me, we created a bunch of giveaways, each with a specific limitation on entry. We had 25 days worth of prizes, and each day held a different challenge. We used comments as the main way to enter, and on certain days we wanted to restrict entry to certain [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent <a href="http://androidandme.com/tegra">promo for Android and Me</a>, we created a bunch of giveaways, each with a specific limitation on entry. We had 25 days worth of prizes, and each day held a different challenge. We used comments as the main way to enter, and on certain days we wanted to restrict entry to certain groups of users.</p>
<p>Some days we only wanted users who had added their Twitter account to the profile (a piece of user meta), some days we wanted only members of a certain age to be eligible (a piece of user meta compared to a set value), and overall, we wanted all comments to be from registered users only (private comments on certain WordPress posts).</p>
<p>To accomplish all these things, I came up with the simple hack of creating a slew of conditional checks that surround <a href="http://codex.wordpress.org/Function_Reference/comment_form">comment_form()</a>. If you&#8217;re not familiar, it&#8217;s a function that outputs the comment form itself and is usually found near the bottom of comments.php. It&#8217;s a pretty easy way to control who is commenting, taking away the form. Take a peek a the heavily commented code below (no pun intended) and join me after for some play by play.</p>
<pre name="code" class="php">&lt;?php 
//start by checking for a couple of key pieces of info
$current_user = wp_get_current_user();
$private_comments = get_post_meta($post->ID, 'private_comments', true);
$meta_lock = get_post_meta($post->ID, 'meta_lock', true);
$time_lock = get_post_meta($post->ID, 'time_lock', true);

//if the post has the custom field 'meta_lock'
if ($meta_lock) {
  //check the current user for that meta field
  $user_meta_key =  get_user_meta($current_user->ID, $meta_lock, true);
    if ($current_user->ID AND $user_meta_key) {
      //display the comment form
      comment_form();
      //give an error message (add some flare!)
    } else { echo 'Special users only!'; }

//if the post has the custom field 'time_lock'	
} elseif ($time_lock) {
  //get the age of the user and prepare the age limits
  $user_age=date("Y-m-d", strtotime($current_user->user_registered));
  $age_limit = strtotime($time_lock);
  $account_age = strtotime($user_age);
  
  //if the current user is OLDER than the set limit
  if ($current_user->ID AND $account_age <= $age_limit) {
    //display the comment form
    comment_form();
  //give an error message (add some flare!)
  } else { echo 'Users older than '.$tegra_time.' only!'; }

//if the post has the field 'private_comments'	
} elseif ($private_comments) {
  //check if the user has an ID (aka is signed in)
  if ( $current_user->ID ) {
    //display the comment form
    comment_form();
  //give an error message (add some flare!)
  } else { echo 'Users only!'; }

//no special conditions met, just display the comment form  
} else { comment_form(); } ?&gt;</pre>
<p>Jeeeez that's a scary wall of text! Ok, not really, but compared to just the single line comment_form() we started with it looks pretty major. What we're doing is actually pretty simple. Anytime the template would normally call comment_form, we're getting in the way and checking some settings first.</p>
<p>What settings? Things we set on a post per post (or page) basis, using custom fields. If you'd like to turn on user-only comments, set a custom field 'private_comments' with any value (I usually just go with 'true'). If you'd like to restrict comments based on whether or not a user has a certain meta field, on your post set a custom field with the key 'meta_lock' and a value matching whatever <em>user</em> meta you'd like to filter by. This can be a user's real name, website link, bio, etc. It's a great way to push your users to fill out certain fields of their profile.</p>
<p>One of the funnest challenges we did was based on user age, something you'll see in the snippet above as age_lock. To use it, simply set a custom field on your post with a YYYY-MM-DD format (one year before today's date, for example). When comments.php is rendered, it'll compare the date the user registered with the date you've entered in the field 'age_lock'.</p>
<p>These few examples are really just to get the juices flowing, and to introduce you to the simple hack of conditionally displaying the comment form. There are an infinite number of things you could check or compare, so if you explore and find something killer make sure you come back and share it with us.</p>
<p>So far, I think my favorite use of this technique was tracking user tweets with the service <a href="http://s.rowfeeder.com/eb5cec4ea7h6S">Rowfeeder</a>, which I then used to export a full list of Twitter usernames. Since our accounts let users link their Twitter handle, I was able to check which WordPress accounts had successfully Tweeted and then conditionally allow them to comment. Total score!</p>
]]></content:encoded>
			<wfw:commentRss>http://clarklab.com/posts/wordpress-comment-hacks-user-only-comments-restrict-by-user-age-and-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sort WordPress users by custom meta value with get_users</title>
		<link>http://clarklab.com/posts/sort-wordpress-users-by-custom-meta-value-with-get_users/</link>
		<comments>http://clarklab.com/posts/sort-wordpress-users-by-custom-meta-value-with-get_users/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 00:45:42 +0000</pubDate>
		<dc:creator>clark</dc:creator>
				<category><![CDATA[posts]]></category>
		<category><![CDATA[get_users]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp_user_query]]></category>

		<guid isPermaLink="false">http://clarklab.com/?p=578</guid>
		<description><![CDATA[I&#8217;ll be honest. This one took me a while. I spent a lot of time looking for a solution but there doesn&#8217;t seem to be a whole bunch of discussion around user queries in plain ol&#8217; WordPress. I guess most of the big user action has moved on to bbPress and BuddyPress. For those of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be honest. This one took me a while. I spent a lot of time looking for a solution but there doesn&#8217;t seem to be a whole bunch of discussion around user queries in plain ol&#8217; WordPress. I guess most of the big user action has moved on to bbPress and BuddyPress.</p>
<p>For those of us with a sizable user base contained <em>only</em> inside WordPress however, actually <em>doing</em> things with users takes a bit of elbow grease. I&#8217;m sure all the same possibilities exist, but people don&#8217;t seem to talk or write about them as often, which is where this guide comes in.</p>
<p>Today we&#8217;re going to look at getting WordPress to sort users by a custom meta value, something that would be useful if your users have any sort of scores, totals, or custom profile fields.</p>
<p>Over on <a href="http://androidandme.com">Android and Me</a>, all users have a point total. We then rank all users by that point total and assign everyone a percentile rank. To call up thousands of users based on a custom meta value seemed daunting, and it was, until I got a bit more familiar with <a href="http://codex.wordpress.org/Class_Reference/WP_User_Query">WP_User_Query</a>.</p>
<p><a href="http://codex.wordpress.org/Class_Reference/WP_User_Query">WP_User_Query</a> was introduced in WordPress 3.1 and brings us an easy and flexible way to query our user database. We&#8217;ll be using the function <a href="http://codex.wordpress.org/Function_Reference/get_users">get_users</a>, which is <a href="http://forrst.com/posts/WordPress_WP_User_Query_vs_get_users-6jY">basically a wrapper</a> for WP_User_Query. You&#8217;ll notice <a href="http://codex.wordpress.org/Function_Reference/get_users">the function</a> includes an &#8216;orderby&#8217; parameter, but the only options given are:</p>
<blockquote><p>orderby &#8211; Sort by &#8216;nicename&#8217;, &#8216;email&#8217;, &#8216;url&#8217;, &#8216;registered&#8217;, &#8216;display_name&#8217;, or &#8216;post_count&#8217;.</p></blockquote>
<p>Notice we&#8217;re missing &#8216;meta_key&#8217; or &#8216;meta_value&#8217;, so we&#8217;re on our own when it comes to ordering these guys by a custom field. Also of note is &#8216;post_count&#8217;, which I could totally see coming in handy on certain community blogs (MAKE A NOTE!). Now that we know what we&#8217;re after and what tools we&#8217;ll need to make it happen, it&#8217;s time we get started.</p>
<h2 id="codestuff">The Code</h2>
<pre name="code" class="php">&lt;?php 
//these are the arguments for the get_users function below
$args  = array(
  'fields' => 'all_with_meta',
  'meta_query' => array(
    array(
    'key' => 'points', // the meta field (or key) we want to target
    'value' => '2',    // the value we want to target (optional)
    'compare' => '>='  // comparison method (optional:  =, >, <, etc)
    )
));

//get_users calls WP_User_Query and returns an array of matching users
$users = get_users($args;)

//custom function for comparing the data we want to sort by
function cmp($a, $b){
  if ($a->points == $b->points) {
    return 0;
  }
  return ($a->points > $b->points) ? -1 : 1;
}

//usort sorts our $users array with our function cmp()
usort($users, 'cmp');

//leaving an array of $users sorted by the value of meta 'points'
foreach ($users as $user) {  
  // do something rad!
} ?&gt;</pre>
<p>I've commented the code above so hopefully you were able to follow along in the actual markup, but if you'd like a short summary: here we go!</p>
<p>I start off with a short list of arguments, or options, that get_users() needs to return the users I want. A full list of parameters can be found on the <a href="http://codex.wordpress.org/Function_Reference/get_users">get_users page</a> in the Codex. The key here is <em>meta_query</em>, which lets me specify the user meta field I'd like to target and compare. I so happen to be calling up users based on their point totals, so I call any user with points above or equal to 2 (any below that I can assume is a scrub and just rank at the bottom of the pile to save some query juice).</p>
<p>Once I've got my $args, I go ahead and run get_users($args). Doing so will return a full list of users that match the arguments, all handily stored in the array $users.</p>
<p>But what's that? They aren't <em>sorted</em>? While we were allowed to compare points while calling the users, no actual sorting took place. This is where we get a bit tricky. Instead of relying on WordPress to sort the users for us, something the Codex says isn't possible right now, we're going to bust out PHP's <a href="http://php.net/manual/en/function.usort.php">usort</a> along with a simple custom function for comparing the points.</p>
<p>Our custom function, cmp(), is just a little check that runs that compares the point total of a user with the other point totals in the array. If the totals are the same, the function returns '0'. If they are different, the function returns a '1' or '-1'. That simple math is enough to let usort crunch through thousands of users in seconds, something I'd spent a couple weeks trying to figure out how to make WordPress do for me. Oh well, <em>you know how that goes.</em></p>
<p>Now that we've got $users in order by the meta field 'points', all that's left is to do something rad. Simply use a <a href="http://php.net/manual/en/control-structures.foreach.php">foreach</a> (PHP's version of The Loop) to run through the users in the array and accomplish something. In my case, it was doing even a bit more math to calculate each user's percentile in order to show what everyone's point totals really meant in relation to one another.</p>
<p>I know not everyone's blog has a point system, but if you've got any amount of users or even multiple authors this might come in handy. I used WP_User_Query all over the place on the <a href="http://wordupaustin.com">WordUp Austin</a> site. On <a href="http://androidandme.com">Android and Me</a>, I list the author pictures in the sidebar. Now, if I wanted to, I could order them by post count or point totals.</p>
<p>Slowly but surely I'm accumulating bits of community-focused solutions like this one and soon I'll be able to say with complete certainty that my WordPress install would slay any bbPress or BuddyPress install you can toss at it.</p>
]]></content:encoded>
			<wfw:commentRss>http://clarklab.com/posts/sort-wordpress-users-by-custom-meta-value-with-get_users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intelligent caching of changing data with the WordPress Transients API</title>
		<link>http://clarklab.com/posts/intelligent-caching-of-changing-data-with-the-wordpress-transient-api/</link>
		<comments>http://clarklab.com/posts/intelligent-caching-of-changing-data-with-the-wordpress-transient-api/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 04:37:40 +0000</pubDate>
		<dc:creator>clark</dc:creator>
				<category><![CDATA[posts]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://clarklab.com/?p=570</guid>
		<description><![CDATA[Recently I built a shortcode for displaying data from the Android Market. You can see it in action on Android and Me. To make the magic happen, I query the AppAware API for a couple key bits of data, mainly the app icon, title, developer name, etc. After a while, I realized that even without [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I built a shortcode for displaying data from the Android Market. You can see it in action on <a href="http://androidandme.com/2011/11/applications/launching-an-app-is-totally-as-fun-as-it-looks-from-beta-to-20k-downloads-in-two-weeks/">Android and Me</a>. To make the magic happen, I query the <a href="http://appaware.org">AppAware</a> API for a couple key bits of data, mainly the app icon, title, developer name, etc.</p>
<p>After a while, I realized that even without a rate limit being imposed by AppAware, some of my calls were failing. To lighten the load, I turned to the <a href="http://codex.wordpress.org/Transients_API">WordPress Transients API</a>, a super simple way of saving (or caching) data for later use. Because saving a transient stores the data locally, you won&#8217;t need to make as many external calls, which is good for you and for your API partners.</p>
<h2>What is the Transients API?</h2>
<p>If you&#8217;re an experienced developer and you&#8217;re familiar with the concept of caching, you can probably skip this section. The code samples are below. But if you don&#8217;t know a thing about saving data locally, WordPress says: <em>the Transients API offers a simple and standardized way of storing cached data in the database temporarily by giving it a custom name and a timeframe after which it will expire and be deleted. Also of note is that Transients are inherently sped up by caching plugins, where normal options are not.</p>
<p>For this reason, transients should be used to store any data that is expected to expire, or which can expire at any time. Transients should also never be assumed to be in the database, since they may not be stored there at all.</em></p>
<p>This makes transients the perfect solution to storing data you would otherwise call from a 3rd party. Ideally, when you need the data, you&#8217;ll first check to see if the transient exists. If it does, you use that data. If it doesn&#8217;t, you call for a fresh version of that data, when you then not only use, but save and timestamp for later use. Sound simple enough?<span id="more-570"></span></p>
<h2>Setting and getting transients</h2>
<p>The main functions we&#8217;ll be using are, predictably, <a href="http://codex.wordpress.org/Function_Reference/set_transient">set_transient</a> and <a href="http://codex.wordpress.org/Function_Reference/get_transient">get_transient</a>, both of which couldn&#8217;t be simpler. To get started, let&#8217;s look at the absolute first step, saving a transient. If you&#8217;ve ever saved meta data using <a href="http://codex.wordpress.org/Function_Reference/update_post_meta">update_post_meta</a> or <a href="http://codex.wordpress.org/Function_Reference/update_user_meta">update_user_meta</a>, this should look totally familiar to you.</p>
<pre name="code" class="php">&lt;?php set_transient( $transient, $value, $expiration ); ?&gt;</pre>
<p>The function accepts three arguments, all of which are pretty straight forward. First, <strong>$transient</strong> is the name of the actual piece of data to be stored. This is the unique ID by which you'll call the data later, so make it good. The <strong>$value</strong> is the actual data being stored, aka the payload. You'll use $expiration to set the time limit on this transient, in seconds. When the time expires, <strong>so does the data</strong>.</p>
<p>Once you've got some data saved, you'll likely want to call it in your templates. Getting a transient is even easier than setting it:</p>
<pre name="code" class="php">&lt;?php get_transient( $transient ); ?&gt;</pre>
<p>Here, again, <strong>$transient</strong> is the unique identifier of the data your looking for. There isn't much to explain here. When you call the transient, if the time limit hasn't expired, you'll have the data to do as you please. If the data has expired and you still need it, things get a tiny bit more complex, which brings us to my next point...</p>
<h2>Putting it all together</h2>
<p>Our sample case will be displaying our <a href="http://klout.com">Klout</a> score, via the <a href="http://developer.klout.com/api_gallery">Klout API</a>. Like I said, this Transients API should be used for time-sensitive data, data that changes or that needs to be refreshed at a reliable interval. And while we're discussing use, it doesn't have to be external data, you could use it to store just about anything. We're just going the API route during the example to score some bonus points.</p>
<p>I've heavily commented the code below, but the basic path goes like this. First, we'll attempt to call the transient. If the data exists, our job is done and we use it. If the data doesn't exist or has expired, we'll call for a fresh copy from the Klout API, which we'll then save and immediately use.</p>
<p>The entire process is basically an <a href="http://php.net/manual/en/control-structures.if.php">if</a> statement that uses both <a href="http://codex.wordpress.org/Function_Reference/set_transient">set_transient</a> and <a href="http://codex.wordpress.org/Function_Reference/get_transient">get_transient</a>.</p>
<pre name="code" class="php">&lt;?php //let's get my klout score!!

//first, let's see if I've got the data already cached locally
$klout = get_transient("klout"); 
  
  //dang it! it looks like I might not. let's check with the Klout API
  if( !$klout ) {  
    $json = file_get_contents("http://api.klout.com/1/klout.json?key=[API key]&users=clarklab");
    $return = json_decode($json, true);
    $kloutscore = $return["users"][0]["kscore"]; 

    //if the Klout API gave us a score, let's save it!
    if( $kloutscore ) {
      
      //in a field named "klout", we'll save our $kloutscore, for 12 hours (60 seconds x 60 minutes x 12 hours)
      set_transient("klout", $kloutscore, 60 * 60 * 12);

      //let's also make sure to set the data you were originally looking for
      $klout = $kloutscore;  
    }  
  }
	
echo 'Now I can safely check my '.$klout.' score with transients!'; ?&gt;</pre>
<p>The main check is <strong>if( !$klout )</strong>, which, of course, checks to see if the value <strong>$klout</strong> is set, which we attempted to do with <a href="http://codex.wordpress.org/Function_Reference/get_transient">get_transient</a>. If it is not, we know we need to fetch a fresh copy of the data and save it (<a href="http://codex.wordpress.org/Function_Reference/set_transient">set_transient</a>). Since we're using a private API, you'll need to replace [API key] with your personal API key (duh).</p>
<p>If you wanted to get fancy, you could always work in the <a href="http://codex.wordpress.org/Function_Reference/delete_transient">delete_transient</a> function, but since these things expire with time I'm content to be the lazy type and just let decay do its work.</p>
<h2>Go forth and cache</h2>
<p>Equipped with your new army of drifter data you're ready to speed up page loads by reducing reliance on often slow external API calls. And if you're dealing with a rate-limited API, caching is a necessity, so you might as well do it with a supported <a href="http://codex.wordpress.org/Transients_API">WordPress API</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://clarklab.com/posts/intelligent-caching-of-changing-data-with-the-wordpress-transient-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using PHP to find a discount on a price in WordPress</title>
		<link>http://clarklab.com/posts/using-php-to-find-a-discount-on-a-price-in-wordpress/</link>
		<comments>http://clarklab.com/posts/using-php-to-find-a-discount-on-a-price-in-wordpress/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 02:26:40 +0000</pubDate>
		<dc:creator>clark</dc:creator>
				<category><![CDATA[posts]]></category>
		<category><![CDATA[deals]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://clarklab.com/?p=568</guid>
		<description><![CDATA[In today&#8217;s version of programming 101, we&#8217;re going to learn how to find the discount on a deal price. It&#8217;s pretty standard fare, but as someone who isn&#8217;t the sharpest mathematician, I figured this might be worth sharing, if for no other reason that I&#8217;ll probably need to look it up at some point in [...]]]></description>
			<content:encoded><![CDATA[<p>In today&#8217;s version of programming 101, we&#8217;re going to learn how to find the discount on a deal price. It&#8217;s pretty standard fare, but as someone who isn&#8217;t the sharpest mathematician, I figured this might be worth sharing, if for no other reason that I&#8217;ll probably need to look it up at some point in the future.</p>
<p>For bonus points, my example will be pulling the prices from a custom field on a WordPress post using get_post_meta. If you&#8217;re not running WordPress, you could just include the plain text prices in the script (where I set $deal_price and $old_price).</p>
<div id="gist-1686586" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><span class="nv">$deal_price</span> <span class="o">=</span> <span class="nx">get_post_meta</span><span class="p">(</span><span class="nv">$post</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">,</span> <span class="s1">&#39;deal_price&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">);</span></div><div class='line' id='LC3'><span class="nv">$old_price</span> <span class="o">=</span> <span class="nx">get_post_meta</span><span class="p">(</span><span class="nv">$post</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">,</span> <span class="s1">&#39;old_price&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">);</span></div><div class='line' id='LC4'><span class="nv">$discount</span> <span class="o">=</span> <span class="nx">round</span><span class="p">(((</span><span class="mi">1</span><span class="o">-</span><span class="p">(</span><span class="nv">$deal_price</span> <span class="o">/</span> <span class="nv">$old_price</span><span class="p">))</span><span class="o">*</span><span class="mi">100</span><span class="p">),</span><span class="mi">0</span><span class="p">);</span></div><div class='line' id='LC5'><span class="k">echo</span> <span class="nv">$discount</span><span class="o">.</span><span class="s1">&#39;%&#39;</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x"></span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1686586/c646511944a839ee5bce3d42cf7cf3870742c923/wordpress-find-discount.php" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1686586#file_wordpress_find_discount.php" style="float:right;margin-right:10px;color:#666">wordpress-find-discount.php</a>
            <a href="https://gist.github.com/1686586">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>If you recall math class, to find a percentage you first divide the new price by the old price. Then to find the <em>discount</em>, you subtract from one and multiply by 100, leaving you with the actual percentage discount on the original price (rounding to zero decimal places).</p>
<p>Again, this is a simple one, I just wanted to log it for posterity&#8217;s sake.</p>
]]></content:encoded>
			<wfw:commentRss>http://clarklab.com/posts/using-php-to-find-a-discount-on-a-price-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What type of WordPress theme should I make?</title>
		<link>http://clarklab.com/posts/what-type-of-wordpress-theme-should-i-make/</link>
		<comments>http://clarklab.com/posts/what-type-of-wordpress-theme-should-i-make/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 20:12:52 +0000</pubDate>
		<dc:creator>clark</dc:creator>
				<category><![CDATA[posts]]></category>
		<category><![CDATA[poll]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://clarklab.com/?p=567</guid>
		<description><![CDATA[In the next few weeks, I&#8217;m going to make a series of three WordPress themes for public consumption, and I need some quick advice on which type of theme you&#8217;d like to see me release. I&#8217;m fairly certain theme one will be a news theme, and theme two will be a portfolio theme, but theme [...]]]></description>
			<content:encoded><![CDATA[<p>In the next few weeks, I&#8217;m going to make a series of three WordPress themes for public consumption, and I need some quick advice on which type of theme you&#8217;d like to see me release. I&#8217;m fairly certain theme one will be a news theme, and theme two will be a portfolio theme, but theme three is still in the air.</p>
<p>The themes will be fully responsive for perfect performance on all devices and will have only a minimal set of theme options (which will be completely removable, if desired, like I would). A good bit of the design is going to be done by <a href="http://twitter.com/angiedoes">@angiedoes</a>, so I know things will come out looking sharp.<span id="more-567"></span></p>
Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.
<p>Sound off in the comments below if you&#8217;ve got some extra ideas. I&#8217;m starting the builds pretty soon and I&#8217;m still open to feature suggestions&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://clarklab.com/posts/what-type-of-wordpress-theme-should-i-make/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Notes from WordUp session: Cultivating Community</title>
		<link>http://clarklab.com/posts/notes-from-wordup-session-cultivating-community/</link>
		<comments>http://clarklab.com/posts/notes-from-wordup-session-cultivating-community/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 01:20:52 +0000</pubDate>
		<dc:creator>clark</dc:creator>
				<category><![CDATA[posts]]></category>
		<category><![CDATA[austin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordUp]]></category>

		<guid isPermaLink="false">http://clarklab.com/?p=565</guid>
		<description><![CDATA[The following are some key links from my talk on Cultivating Community at WordUp Austin on January 21, 2012. You can find the slides over on Google Docs, but the real magic came in person that one fateful morning&#8230; Ask questions Topic Tueday &#8211; A new question once a week that is locked to comments [...]]]></description>
			<content:encoded><![CDATA[<p>The following are some key links from my talk on Cultivating Community at WordUp Austin on January 21, 2012. You can find the <a href="https://docs.google.com/present/edit?id=0AaJR_R1Sv5FhZGNwY3NrZ3hfNDNjMzZucmpmbQ">slides over on Google Docs</a>, but the real magic came in person that one fateful morning&#8230;</p>
<h3>Ask questions</h3>
<p><a href="http://androidandme.com/tag/topic-tuesday/">Topic Tueday</a> &#8211; A new question once a week that is locked to comments from users only. A point multiplier is also in effect.</p>
<h3>Poll Your Audience</h3>
<p><a href="http://polldaddy.com/">PollDaddy</a> &#8211; A powerful and easy to use poll plugin maintained by Automattic.<br />
<a href="http://wordpress.org/extend/plugins/wp-polls/">WP-Polls</a> &#8211; A lightweight poll plugin written by Lester &#8216;Gamerz&#8217; Chan.</p>
<h3>Identity / Influence</h3>
<p><a href="http://androidandme.com/user/clark">And Me Account</a> &#8211; A sample account from my site, showing real name, user pic, user score, percentile rank, and links to various social accounts.<br />
<a href="http://gravatar.com">Gravatar</a> &#8211; A widely used avatar service maintained by Automattic.<br />
<a href="http://cubepoints.com">Cubepoints</a> &#8211; A lightweight point tracking system with modules that make for easy customization.<br />
<a href="http://www.bunchball.com/">Bunchball</a> &#8211; Full-bore gamification with badges and achievements and all that stuff.</p>
<h3>Contests</h3>
<p><a href="http://wordpress.org/extend/plugins/pick-giveaway-winner/">Pick Giveaway Winner</a> &#8211; A super simple plugin for running bespoke contests with user comments.<br />
<a href="http://androidandme.com/tegra">25 Days of Tegra</a> &#8211; My biggest promo to date, where we gave away a device per day only to users, generating tens of thousands of user interactions.<br />
<a href="http://androidandme.com/hackthenews/">#HackTheNews</a> &#8211; A sample contest I ran on Android and Me where users could tweet stories with tweaked headlines, generating over 1k tweets in barely a week.<br />
<a href="http://androidandme.com/tag/midweek-madness/">Midweek Madness</a> &#8211; A weekly contest with usually small prizes.</p>
<h3>Do Things with your Users</h3>
<p><a href="http://codex.wordpress.org/Class_Reference/WP_User_Query">wp_user_query</a> &#8211; A new (since 3.1) query class for working with users. Makes things super simple (compared to the old ways, at least).<br />
<a href="http://codex.wordpress.org/Function_Reference/update_user_meta">update_user_meta</a> &#8211; A super-handy function for adding and updating extra information to any user account. Use with <a href="http://codex.wordpress.org/Function_Reference/get_user_meta">get_user_meta</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://clarklab.com/posts/notes-from-wordup-session-cultivating-community/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a vanity URL in WordPress with a simple page redirect</title>
		<link>http://clarklab.com/posts/how-to-create-a-vanity-url-in-wordpress-with-a-simple-page-redirect/</link>
		<comments>http://clarklab.com/posts/how-to-create-a-vanity-url-in-wordpress-with-a-simple-page-redirect/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 17:18:38 +0000</pubDate>
		<dc:creator>clark</dc:creator>
				<category><![CDATA[posts]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://clarklab.com/?p=561</guid>
		<description><![CDATA[Hey guys, I&#8217;ve got a super simple WordPress tip for you today that has come in handy numerous times over the years. In this age of short URLs, there are often times when you&#8217;ll need a top-level, &#8220;pretty&#8221; URL on your main domain that points to a longer, more complex URL. For example, we are [...]]]></description>
			<content:encoded><![CDATA[<p>Hey guys, I&#8217;ve got a super simple WordPress tip for you today that has come in handy numerous times over the years. In this age of short URLs, there are often times when you&#8217;ll need a top-level, &#8220;pretty&#8221; URL on your main domain that points to a longer, more complex URL.</p>
<p>For example, we are about to start an affiliate campaign with WPEngine, and my affiliate linked looked like this: <a href="http://wpengine.com?a_aid=4e6fc813411ff">http://wpengine.com?a_aid=4e6fc813411ff</a>, which isn&#8217;t very pretty. I&#8217;d much rather link to a nice looking URL such as <a href="http://androidandme.com/wpe">http://androidandme.com/wpe</a>, which will read better in banners, in videos, and when being said aloud.</p>
<p>To get this done, we&#8217;re just going to make a simple custom <a href="http://codex.wordpress.org/Pages#Page_Templates">page template</a> that uses a simple PHP command to tell the browser that the page has moved. Take the following code and save it inside your main template folder as <strong>page-redirect.php</strong>:</p>
<pre name="code" class="php">
&lt;?php
/*
Template Name: Redirect
*/

$redirect_url = get_post_meta($post-&gt;ID, 'redirect_url', true);
if ($redirect_url) {
Header( 'HTTP/1.1 301 Moved Permanently' );
Header( 'Location: '.$redirect_url.'' );
}
?&gt;
</pre>
<p>If you&#8217;ve made a custom page template before, that top part probably looks familiar to you. It&#8217;s the special bit of markup that lets WordPress know that you&#8217;ve defined a new page template, which will make our new template selectable from the &#8216;Edit Page&#8217; screen in /wp-admin.</p>
<p>After that, we call up a custom field, &#8220;redirect_url&#8221;, which contains the long and ugly URL we want to point the browser to. Following the retrieval of that value, we use a PHP <a href="http://php.net/manual/en/function.header.php">header</a> function to send the user along to the new page.</p>
<h3>Using your new custom template</h3>
<p><img src="http://clarklab.com/wp-content/uploads/2011/12/page-template.png" alt="" title="page-template" width="289" height="257" class="alignleft size-full wp-image-562" />To actually use this new custom template, there are just a few quick steps. When creating a new page, make sure that you select your custom template. There will be a drop-down in the right column where you can select your &#8220;Redirect&#8221; template (see image).</p>
<p>Also make sure that your set your page slug to something pretty. If you&#8217;re page is titled &#8220;Hey check out my new link&#8221;, your url slug will be hey-check-out-my-new-link. Don&#8217;t do that. Make the slug something simple, like &#8220;wpe&#8221;.</p>
<p>All that&#8217;s left now is to enter your long, ugly URL into a <a href="http://codex.wordpress.org/Custom_Fields">custom field</a> labeled with the key of &#8220;redirect_url&#8221;. If you&#8217;ve never done it before, fear not, because it&#8217;s a much simpler process than people make it out to be. All you need to do is locate the &#8220;Custom Fields&#8221; box on the &#8220;Edit Page&#8221; screen and enter a key and value pair. The key is the title, &#8220;redirect_url&#8221;, and the value is the new URL, in this case: <a href="http://wpengine.com?a_aid=4e6fc813411ff">http://wpengine.com?a_aid=4e6fc813411ff</a></p>
<p>The great thing about this technique is it will work with any URL and doesn&#8217;t require a plugin. We use the technique lots of times internally, linking to our own specific posts with long URLs. As I mentioned above, it&#8217;s a great technique for video or a podcast, where you&#8217;ve actually got to say aloud <em>Don&#8217;t forget to check out <a href="http://androidandme.com/wpe">androidandme.com/wpe</a> for a great deal on WordPress hosting</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://clarklab.com/posts/how-to-create-a-vanity-url-in-wordpress-with-a-simple-page-redirect/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting custom with Google Currents</title>
		<link>http://clarklab.com/posts/getting-custom-with-google-currents/</link>
		<comments>http://clarklab.com/posts/getting-custom-with-google-currents/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 00:54:22 +0000</pubDate>
		<dc:creator>clark</dc:creator>
				<category><![CDATA[posts]]></category>
		<category><![CDATA[Currents]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://clarklab.com/?p=552</guid>
		<description><![CDATA[Yesterday Google announced Currents, a ridiculously awesome feed-reader-magazine-type thing that I think is shaping up to be pretty damn disruptive. In an attempt to really throw some egg in the faces of their competition, they&#8217;ve also rolled out the Google Currents Producer, giving content owners point-and-click, app-creating powers. Google Currents is available for Android and [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday Google announced <a href="http://googlemobile.blogspot.com/2011/12/google-currents-is-hot-off-press.html">Currents</a>, a ridiculously awesome feed-reader-magazine-type thing that I think is shaping up to be pretty damn disruptive. In an attempt to really throw some egg in the faces of their competition, they&#8217;ve also rolled out the <a href="https://plus.google.com/u/0/101062235821996561929/posts/6aMBXD6EeCB">Google Currents Producer</a>, giving content owners point-and-click, app-creating powers.</p>
<p>Google Currents is available for Android and iOS, both phones and tablets, meaning pretty much every big blog on the planet is going to be rolling onto Currents in the next few weeks. If you&#8217;d like to stand out, you&#8217;re gonna have to get your hands dirty.</p>
<p>The good news is that Google Currents is pretty well documented, especially for a product right out of the gate, and it uses a bunch of technology you&#8217;re probably already familiar with (Well, if you&#8217;re a web dev, that is). Every single view (table of contents, lists, articles, etc) are templated for complete control, allowing changes with simple CSS, HTML, and HTML-like markup. I say <em>HTML-like</em> because I thought these XML namespaces like <span style="font-family: 'Courier New'; font-weight: bold;">&lt;g:field&gt;</span> looked familiar enough that if you know HTML you should be comfortable inside Currents.</p>
<h2 id="lingo">Some Current Lingo</h2>
<p>Before we get started, I&#8217;m going to ramble off some lingo that I&#8217;ve picked up in the last day. Since the app is called Currents, I&#8217;ve seen lots taking to calling a single instance a <em>Current</em>. The actual term appears to be <em>Edition</em>, but I&#8217;ll probably be using them both interchangeably. Like I mentioned above, the tool to created a custom edition is called the Google Currents Producer, and can be found at <a href="http://google.com/producer">http://google.com/producer</a>.</p>
<p>I should also mention that this guide is aimed squarely at folks that have already logged into <a href="http://google.com/producer">Producer</a> and poked around some. Nothing that follows is crazy complex, but it might look weird if you&#8217;ve not even seen the Producer flow. Get in there and play around some!</p>
<p>Once you&#8217;ve created an edition, you&#8217;ll be able to add <em>sections</em> from some predefined choices, like Feed (RSS or Atom), Articles (Google Docs or HTML), Photos (feeds from services like Flickr), Videos (from YouTube), or Social Updates (Google+ built-in or RSS for things like Twitter). Setting up your sections is mostly a point-and-click process, so I won&#8217;t really be covering it in much detail here.</p>
<p>You can create and organize as many <em>Sections</em> as you want, along with a special <em>Table of Contents</em> section, which shows the most recent updates from all the other sections. Like I said earlier, nearly every single view here is templated. Each section can have individual templates (tabloid, list, photos, etc), along with templates for things like the <em>section header</em> and the <em>article template</em>. One thing I&#8217;ve noticed almost all Currents doing is defining a custom header template, so let&#8217;s start there.</p>
<h2 id="customheader">Creating a Custom Header Template in Google Currents</h2>
<p>Once you&#8217;ve got a section created (be it a feed, videos, or table of contents), you&#8217;ll probably want to slap a custom header on that bad boy. Setting it up is actually pretty easy but I found a couple &#8220;gotchas&#8221; I wanted to detail here (mainly so that other Editions I&#8217;ve subscribed to will use them, haha).</p>
<p>When you first create a section, the header template will be set to &#8220;Default&#8221;. Using the drop down, change that to &#8220;Custom&#8221; and have a look around. Most of the markup, should look pretty familiar, and the piece you&#8217;re looking for specifically should be near the bottom, with the class CustomHeader</p>
<p>[html]<br />
&lt;div class=&#8217;customHeader&#8217;&gt;<br />
  &lt;div class=&#8217;editionName&#8217;&gt;<br />
    &lt;g:text textid=&#8217;editionName&#8217;&gt;&lt;/g:text&gt;<br />
  &lt;/div&gt;<br />
  &lt;div class=&#8217;divider&#8217;&gt;&lt;/div&gt;<br />
  &lt;div class=&#8217;sectionName&#8217;&gt;<br />
    &lt;g:text textid=&#8217;sectionName&#8217;&gt;&lt;/g:text&gt;<br />
  &lt;/div&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>That&#8217;ll give us our first glance at some of the Currents Producer template tags, which commonly start with <span style="font-family: 'Courier New'; font-weight: bold;">&lt;g:</span> and end with some logical suffix. You can find a <a href="http://support.google.com/producer/bin/answer.py?hl=en&amp;answer=1636194&amp;topic=1694363&amp;ctx=topic">full list here</a>, along with an abbreviated version right inside the Producer by clicking &#8220;Insert Tags&#8221;.</p>
<p>The above markup will output my Edition&#8217;s name <em>and</em> the specific section name, split by a divider (you&#8217;ll find the divider CSS at the top of the template file). I&#8217;m not sure if you guys need to even see this step, but for the sake of illustration, the above code would render the following:</p>
<p>[html]<br />
&lt;div class=&#8217;customHeader&#8217;&gt;<br />
  &lt;div class=&#8217;editionName&#8217;&gt;<br />
    Android and Me<br />
  &lt;/div&gt;<br />
  &lt;div class=&#8217;divider&#8217;&gt;&lt;/div&gt;<br />
  &lt;div class=&#8217;sectionName&#8217;&gt;<br />
    Latest News<br />
  &lt;/div&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>While styling the header is just a matter of applying some simple CSS to <span style="font-family: 'Courier New'; font-weight: bold;">.customHeader</span>, there are a few other things we can do here. First, if you&#8217;ve seen our mobile site, you know we don&#8217;t even display our title text, just a logo. So that first <span style="font-family: 'Courier New'; font-weight: bold;">&lt;g:text&gt;</span> will be getting the boot.</p>
<p>Also, something you might not notice until you use the Edition inside the app itself, <strong>there is no link to the index on the main title</strong>, something that drives me crazy. Virtually all websites use that convention, most apps do, too, so I wanted it in my Current. Since I now just have a main logo and section title, I no longer need the divider, so it gets the boot as well. My new section header looked like this:</p>
<p>[html]<br />
&lt;div class=&#8217;customHeader&#8217;&gt;<br />
&lt;g:link toc=&quot;true&quot; class=&quot;logo&quot;&gt;&lt;/g:link&gt;<br />
  &lt;div class=&#8217;title&#8217;&gt;<br />
    &lt;g:text textid=&#8217;sectionName&#8217;&gt;&lt;/g:text&gt;<br />
  &lt;/div&gt;<br />
&lt;/div&gt;<br />
[/html]</p>
<p>I&#8217;m using <span style="font-family: 'Courier New'; font-weight: bold;">&lt;g:link&gt;</span> to link back to the table of contents. If you&#8217;d like to see what else you can link to, check out the documentation on <a href="http://support.google.com/producer/bin/answer.py?hl=en&amp;answer=1636194&amp;topic=1694363&amp;ctx=topic#g-link">g:link</a> or try the &#8220;Insert Tags&#8221; popup directly within Producer. I classed the link with &#8220;logo&#8221; so that I&#8217;d be able to target it with CSS, and the rest was simple styling:</p>
<p>[css]<br />
&lt;style&gt;<br />
.customHeader { display:block; height:50px; position:relative; background:#000;}<br />
.customHeader .title{color:#ccc; position:absolute; top:13px; right:20px;}<br />
.customHeader .logo{position:absolute; top:0; left:0; width:58px; height:60px; background:url(attachment/CAAqBggKMPSRFDCRyQI-logo-corner.png) no-repeat; background-size:100% 100%;}<br />
&lt;/style&gt;<br />
[/css]</p>
<p>If you notice that weird-looking path in there (attachment/CAAqBggKMPSRFDCRyQI-logo-corner.png), you might be sort of scared, but Producer makes uploading assets pretty dang simple. There is a media manager and every image uploaded is displayed with a path you can use in your custom markup. Simply upload your logo and grab its path from the &#8220;Insert Tags&#8221; popup available directly inside Producer.</p>
<p><a href="http://clarklab.com/wp-content/uploads/2011/12/clarklab-currents-1.png"><img class="alignleft size-full wp-image-555" title="clarklab-currents-1" src="http://clarklab.com/wp-content/uploads/2011/12/clarklab-currents-1.png" alt="" width="274" height="305" /></a>The result is a custom header, with a logo that links to your TOC section, along with a dynamic title for the section you&#8217;re viewing. We named ours <em>Current Edition</em>, which you can see in the preview to the left. If you were in the Devices section, it would read Devices, thanks to our <span style="font-family: 'Courier New'; font-weight: bold;">&lt;g:text&gt;</span> template tag. All you&#8217;ve gotta do is make a copy of your markup to any sections you want to share this new, custom header.</p>
<p>There are still a few catches, like the fact that your custom header template <strong>CANNOT BE TALLER THAN 50PX</strong>. I write that in all caps because I wasted about half an hour last night trying to make it so. Anything more will definitely be cropped, no matter how many <span style="font-family: 'Courier New'; font-weight: bold;">overflow:show !important</span>&#8216;s you add. It&#8217;s a rule I finally found on this official Google helpdoc cleverly titled <a href="http://support.google.com/producer/bin/answer.py?hl=en&amp;answer=1633985&amp;topic=1694363&amp;ctx=topic">Add a custom header</a>. If my description was too breezy or if you need more help, I&#8217;d recommend consulting that doc. I&#8217;d also recommend setting up a custom header as a nice first exercise. Adding a logo to the Google Currents header is a great way to dip your toe into the pool before experimenting with more complex template tags. Speaking of which&#8230;</p>
<h2 id="related">Creating a list of related posts in a Google Currents article template</h2>
<p>Earlier I was saying that if you were comfy with HTML that you&#8217;d be fine inside of Currents. What I really meant was if you know HTML and are at least a <em>tiny bit</em> comfortable with PHP or WordPress then you&#8217;ll be fine. Creating a list of related posts is going to make use of a loop, something that should be familiar to any blog developer.</p>
<p>To loop through the related posts, we&#8217;re going to make use of the <a href="http://support.google.com/producer/bin/answer.py?hl=en&amp;answer=1636194&amp;topic=1694363&amp;ctx=topic#g-related">g:related</a> template tag, another find from <a href="http://support.google.com/producer/">the official Google helpdocs</a>. Seriously, bookmark that thing. Anyway, after switching it to &#8220;Custom&#8221;, we&#8217;re going to drop the following into the bottom of our Article Template:</p>
<p>[html]<br />
&lt;h2&gt;Related posts&lt;/h2&gt;<br />
&lt;g:related max=&quot;3&quot;&gt;<br />
&lt;p&gt;&lt;g:relatedLink&gt;<br />
&lt;g:relatedField fieldId=&quot;title&quot;/&gt;<br />
&lt;/g:relatedLink&gt;<br />
&lt;span&gt;&lt;g:relatedField fieldId=&#8217;created&#8217;/&gt;&lt;/span&gt;<br />
&lt;/p&gt;&lt;/g:related&gt;<br />
[/html]</p>
<p>In the above example, the tag <span style="font-family: 'Courier New'; font-weight: bold;">&lt;g:related&gt;</span> will find the 3 most recent related posts and display them, along with a timestamp, at the end of the article template.</p>
<p><img class="alignright size-full wp-image-557" title="clarklab-currents-related" src="http://clarklab.com/wp-content/uploads/2011/12/clarklab-currents-related.png" alt="" width="285" height="236" /> One thing to note, is that when inside a related loop, all the template tags change and get an extra &#8220;related&#8221; prefix. For example, <span style="font-family: 'Courier New'; font-weight: bold;">&lt;g:field&gt;</span> becomes <span style="font-family: 'Courier New'; font-weight: bold;">&lt;g:relatedField&gt;</span> and so on. Without the prefix, the values returned will reflect the original individual article being displayed, not that of the returned related post. It&#8217;s a small difference but a very important one. Make a mental note. Now.</p>
<p>While I didn&#8217;t exactly take the time to style these yet, at this point, it would just be a simple job of applying some CSS. I&#8217;m mainly just jazzed to have it working, as learning the Producer loop methodology is the first step in making my own custom TOC, tabloid, and list templates. For now, I’m not exactly sure what the match criteria is (topic, author, date, etc) but the articles seem to be relevant so I&#8217;m rolling with it.</p>
<h2 id="external">Creating a link to an external site in Google Currents</h2>
<p>One thing I noticed almost immediately and didn&#8217;t really like was that <em>a lot</em> of articles don&#8217;t display a link back to the main site anywhere. On top of that, Currents doesn&#8217;t have a way for users to add or even view comments from inside the app. Those drawbacks added up to an absolute need for a button that let users visit the original article.</p>
<p>Oddly enough, I see some remnant styling of a button, classed <span style="font-family: 'Courier New'; font-weight: bold;">.seeOriginalLink</span>, but I don&#8217;t see that anywhere in my templates. I&#8217;ve seen this magical button floating around in some Currents, live, but I&#8217;ve got no idea what triggers it or when it appears. What I knew for certain was that my WordPress-provided feed somehow wasn&#8217;t triggering them and I wanted them. So I did some digging and found a JS function that will launch an external link in Google Currents:</p>
<p>[html]<br />
&lt;a class=&quot;available-width-100&quot; onclick=&quot;google.studio.openOriginalUrl();&quot;&gt;View on Androidandme.com&lt;/a&gt;<br />
[/html]</p>
<p>Two things of note here: I used a JS onclick to fire the function and I utilized the Producer-provided class <span style="font-family: 'Courier New'; font-weight: bold;">.available-width-100</span>. The JS will open the original URL in an internal browser, along with a button to launch the site in the user&#8217;s default browser. I&#8217;d much rather launch straight to the default browser (so if anyone has figured that out, please let me know) but for now, I&#8217;ll take it.</p>
<p><img class="alignleft size-full wp-image-558" title="clarklab-curernts-button" src="http://clarklab.com/wp-content/uploads/2011/12/clarklab-curernts-button.png" alt="" width="274" height="236" />Using <span style="font-family: 'Courier New'; font-weight: bold;">.available-width-100</span> means that my button will fill all of the available space, be it full-screen or column. You can change that integer to any number really, I just wanted a full-width button. There are other special classes, like <span style="font-family: 'Courier New'; font-weight: bold;">.g-unbreakable</span>, which you can find documented over in the official <a href="http://support.google.com/producer/bin/answer.py?hl=en&amp;answer=1636194&amp;topic=1694363&amp;ctx=topic#css-classes">Google support page</a>.</p>
<p>The result was a nice, green button that will draw users back to <a href="http://androidandme.com">androidandme.com</a>. We have an insanely healthy user community and I wanted to make sure that people were still able to leave comments and upvotes with just a few clicks. If you&#8217;re syndicating a feed into Google Currents, I <em>really</em> think you should always have a link back to the original content, even if Currents sometimes doesn&#8217;t seem to want to provide one.</p>
<h2 id="wordpress">Import WordPress to Google Currents</h2>
<p>I said I wasn&#8217;t really going to talk about this one in depth, and I won&#8217;t, so we&#8217;ve saved the easiest part for last. As you look around at other Currents, you&#8217;ll probably notice that people create a bunch of different sections from one blog. For example, in our Android and Me Current Edition, we&#8217;ve got a section for Latest News, Devices, Apps, etc. We even have special channels like posts from only Taylor or just giveaways from <a href="http://androidandme.com/tegra">The 25 Days of Tegra</a>. Going from WordPress to Google Currents is easier than you&#8217;d think.</p>
<p>The process is really simple, actually, and just requires tracking down all the custom feeds that WordPress already provides for you. Like most of us know, WordPress generates RSS and Atom feeds from recent posts, comments, and more. Every category, every tag, every author has their own feed. You can find them just by tacking /feed onto most URLs. For example, <a href="http://androidandme.com/tag/google">http://androidandme.com/tag/google</a> would be <a href="http://androidandme.com/tag/google/feed">http://androidandme.com/tag/google/feed</a>. Pretty simple, huh? With that special feed URL, you could easily set up a section on only Google news in your Current.</p>
<p>If you&#8217;ve got a special author you&#8217;d like to feature, you could easily use his feed as a custom channel. If you&#8217;ve got a WordPress tag that&#8217;s seeing a lot of action, make a Currents section out of that specific feed. Currents even has its own CMS-style article capability, allowing you to mingle custom, non-WP data in along with your posts, but that&#8217;s probably best saved for another day.</p>
<h2 id="final">So that&#8217;s it. Go make some Currents</h2>
<p>Like I said at the start, I think Google Currents is one of the most gnarly and disruptive things to come down the pipe in quite some time. It allows virtually any content owner to create ridiculously custom Editions in just a matter of minutes. With some practice, I have a feeling we&#8217;re about to see even crazier things out of folks with too much time on their hands. And on those lines, I have a feeling there is about to be a really vibrant market around custom Currents themes.</p>
<p>For now though, I&#8217;m just happy to tinker and share.</p>
]]></content:encoded>
			<wfw:commentRss>http://clarklab.com/posts/getting-custom-with-google-currents/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Create one of those trendy launch pages in WordPress with no plugins</title>
		<link>http://clarklab.com/posts/create-a-launch-page-in-wordpress-with-no-plugins/</link>
		<comments>http://clarklab.com/posts/create-a-launch-page-in-wordpress-with-no-plugins/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 18:00:13 +0000</pubDate>
		<dc:creator>clark</dc:creator>
				<category><![CDATA[posts]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[MailChimp]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://clarklab.com/?p=548</guid>
		<description><![CDATA[I&#8217;m sure you&#8217;ve seen them around: those big, inviting launch pages that sites use to gather leads before a public launch. If you haven&#8217;t, check out Fab.com for a nice example, or take a peek at Launch Effect, one of the more popular WordPress solutions available. In the next few weeks, we&#8217;re planning to launch [...]]]></description>
			<content:encoded><![CDATA[<div class="site alignleft" style="width:392px; height:290px;"><a href="http://androidhire.com/"><span class="title">AndroidHire</span><img class="ss_screenshot_img" alt="http://androidhire.com/" width="400" src="http://s.wordpress.com/mshots/v1/http%3A%2F%2Fandroidhire.com%2F?w=400" /></a></div>
<p>I&#8217;m sure you&#8217;ve seen them around: those big, inviting launch pages that sites use to gather leads before a public launch. If you haven&#8217;t, check out <a href="http://fab.com">Fab.com</a> for a nice example, or take a peek at <a href="http://launcheffectapp.com/">Launch Effect</a>, one of the more popular WordPress solutions available.</p>
<p>In the next few weeks, we&#8217;re planning to launch AndroidHire. We&#8217;ve already got the site online, with a heavily customized theme, and handful of users actively managing job listings. The problem: we wanted to lock everything down to any non-members (while still leaving the main site intact for existing users). Looking around, I saw a handful of plugins (like <a href="http://wordpress.org/extend/plugins/maintenance-mode/">Maintenance Mode</a>) or full-on themes (like <a href="http://launcheffectapp.com/">Launch Effect</a>), but I wanted something lighter. Just a simple way to pick off logged out traffic and redirect them to a nice signup page.</p>
<p>The solution proved to be even easier than I imagined, so much so that I figured a blog post was in order. To sort out the guests, simply drop something like this into the very top of your theme&#8217;s header.php:</p>
<p>[php]<br />
&lt;?php if ( ! is_user_logged_in() AND ! is_page(&#8216;Launch&#8217;)) {<br />
header(&quot;Location: http://androidhire.com/launch&quot;);<br />
exit(); } ?&gt;<br />
[/php]</p>
<p>The first line is a conditional with two statements. First, it checks if the user logged in. If they are not, they are redirected to my &#8220;Launch&#8221; page. Second, it checks if you&#8217;re already on the &#8220;Launch&#8221; page, simply to avoid a redirect loop.</p>
<p>Of course, if your data is <em>highly</em> sensitive, you might want to take some further steps, like disabling RSS feeds or locking down (or moving) the /wp-admin folder. This is just a quick and easy way to create a new landing page without affecting the rest of your active site.</p>
<p>The launch page I made is just a simple signup form that ties to Mailchimp. I&#8217;ve got two options, one for job seekers and one for job posters. Upon launch, I&#8217;ll email out to both lists and hopefully pull some extra attention from an eager crowd.</p>
]]></content:encoded>
			<wfw:commentRss>http://clarklab.com/posts/create-a-launch-page-in-wordpress-with-no-plugins/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

