

<?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>Get into the culture! &#187; tutorial</title>
	<atom:link href="http://wpvibe.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpvibe.com</link>
	<description>Just another EMV Network Site site</description>
	<lastBuildDate>Sun, 26 Feb 2012 22:21:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>HOWTO: Thumbnails for Categories</title>
		<link>http://wpvibe.com/thumbnails-for-categories-180/</link>
		<comments>http://wpvibe.com/thumbnails-for-categories-180/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 22:49:51 +0000</pubDate>
		<dc:creator>Jonathan Dingman</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[thumbnails]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://wpvibe.com/?p=180</guid>
		<description><![CDATA[Customizing a post with a fresh and unique thumbnail is a nice touch as it adds just a bit more personality to the post, rather than having the same ole&#8217; images or not having images at all. Here on WordPress Vibe, we have thumbnails for each post, which both Dre and I really like (and ...]]></description>
			<content:encoded><![CDATA[<p>Customizing a post with a fresh and unique thumbnail is a nice touch as it adds just a bit more personality to the post, rather than having the same ole&#8217; images or not having images at all.  Here on WordPress Vibe, we have thumbnails for each post, which both Dre and I really like (and we hope you like them too <img src='http://wpvibe.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .  Here&#8217;s a short tutorial on how to achieve similar results.</p>
<p>First, you need to decide what resolution you want your thumbnails to be.  For this tutorial, we will be using what we use here on WP Vibe, which is 150px by 150px.</p>
<h3>Step 1:  Create Your Custom Thumbnail Image</h3>
<p>What we do here is we build a separate image that is 150&#215;150 and upload to the specific post.  Then we grab the link URL of the thumbnail image you just uploaded and copy it.</p>
<p>Then close out of that box and head back to the post.  We have a custom field called &#8220;thumb&#8221; which we use, but you can use whatever value you want.</p>
<p>Paste that link into the custom field as the value, such as below:</p>
<p><img src="http://wpvibe.com/wp-content/uploads/2009/12/wordpress-custom-field.jpg" alt="" width="630" height="64" class="aligncenter size-full wp-image-181" /></p>
<p>Next, the actual code to make the magic work.</p>
<h3>Step 2: Integrate the Code</h3>
<p>First, we check to see if the user has input anything into the &#8220;thumb&#8221; custom field for the post, which would be pointing to the thumbnail image.</p>
<p>[sourcecode lang="php"]&lt;?php<br />
$thumb = get_post_meta($post-&gt;ID, &quot;thumb&quot;, true);<br />
if ($thumb != &quot;&quot;) { ?&gt;<br />
	&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; title=&quot;&lt;?php the_title(); ?&gt;&quot; rel=&quot;nofollow&quot;&gt;<br />
	&lt;img src=&quot;&lt;?php $values = get_post_custom_values(&quot;thumb&quot;); echo $values[0]; ?&gt;&quot; alt=&quot;&lt;?php the_title(); ?&gt;&quot; class=&quot;alignleft&quot; /&gt;&lt;/a&gt;<br />
&lt;?php<br />
the_excerpt();<br />
?&gt;[/sourcecode]</p>
<p>Second, if the &#8220;thumb&#8221; field is empty, we run a loop to go through a specified folder of images for our categories.</p>
<p>[sourcecode lang="php"]&lt;?php<br />
$newthumb = &quot;news.png&quot;;<br />
$category = get_the_category();<br />
$catid = $category[0]-&gt;category_nicename;<br />
$okCats = array( &#8216;news&#8217;, &#8216;interviews&#8217;, &#8216;resources&#8217;, &#8216;reviews&#8217; ); //Maybe even filter this so it can be extended<br />
if ( in_array($catid, $okCats) ) {<br />
	$newthumb = strtolower($catid) . &#8216;.png&#8217;;<br />
}<br />
?&gt;[/sourcecode]</p>
<p>The first bit of code, $newthumb = &#8220;news.png&#8221;; is to set a default thumbnail, in case you have a category that doesn&#8217;t have a specific thumbnail.  Next, we grab the current category for the post.  Next, we naturalize the name so it&#8217;s all lowercase and easy for the server to process.</p>
<p>Next, we build the array of categories that we have.  For us, we have &#8220;news&#8221;, &#8220;interviews&#8221;, &#8220;resources&#8221;, etc etc.</p>
<p>We have images made for each category so that it knows what to display for that category.</p>
<p>If an image doesn&#8217;t exist for one of the categories, it will go bac and use the default news.png which we previously specified.  Now, to actually use the thumbnail link which was just built.</p>
<h3>Step 3: Building the Thumbnail Link</h3>
<p>Here is the PHP code which actually displays the image now for each category.</p>
<p>[sourcecode lang="php"]	&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; title=&quot;&lt;?php the_title(); ?&gt;&quot; rel=&quot;nofollow&quot;&gt;<br />
	&lt;img src=&quot;&lt;?php echo get_stylesheet_directory_uri(); ?&gt;/images/thumbs/&lt;?php echo $newthumb; ?&gt;&quot; alt=&quot;&lt;?php the_title(); ?&gt;&quot; class=&quot;alignleft&quot; /&gt;&lt;/a&gt;[/sourcecode]</p>
<p>All the Code Together<br />
Here is what everything looks like together.</p>
<p>[sourcecode lang="php"]&lt;?php<br />
$thumb = get_post_meta($post-&gt;ID, &quot;thumb&quot;, true);</p>
<p>if ($thumb != &quot;&quot;) { ?&gt;</p>
<p>	&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; title=&quot;&lt;?php the_title(); ?&gt;&quot; rel=&quot;nofollow&quot;&gt;<br />
	&lt;img src=&quot;&lt;?php $values = get_post_custom_values(&quot;thumb&quot;); echo $values[0]; ?&gt;&quot; alt=&quot;&lt;?php the_title(); ?&gt;&quot; class=&quot;alignleft&quot; /&gt;&lt;/a&gt;<br />
&lt;?php<br />
the_excerpt();<br />
} else {<br />
$newthumb = &quot;news.png&quot;;<br />
$category = get_the_category();<br />
$catid = $category[0]-&gt;category_nicename;<br />
$okCats = array( &#8216;news&#8217;, &#8216;interviews&#8217;, &#8216;resources&#8217;, &#8216;reviews&#8217; ); //Maybe even filter this so it can be extended<br />
if ( in_array($catid, $okCats) ) {<br />
	$newthumb = strtolower($catid) . &#8216;.png&#8217;;<br />
}</p>
<p>?&gt;<br />
	&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; title=&quot;&lt;?php the_title(); ?&gt;&quot; rel=&quot;nofollow&quot;&gt;<br />
	&lt;img src=&quot;&lt;?php echo get_stylesheet_directory_uri(); ?&gt;/images/thumbs/&lt;?php echo $newthumb; ?&gt;&quot; alt=&quot;&lt;?php the_title(); ?&gt;&quot; class=&quot;alignleft&quot; /&gt;&lt;/a&gt;<br />
&lt;?php the_excerpt(); } ?&gt;[/sourcecode]<br />
<strong><br />
In the end, you have a way of ensuring you always have a thumbnail appropriate to the post category, and the option to customize per post</strong></p>
<p>Any comments or suggestions, please feel free to leave them in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://wpvibe.com/thumbnails-for-categories-180/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

