<?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>Pixellica: Creativity Blooms &#187; plugin</title>
	<atom:link href="http://www.pixellica.com/tag/plugin/feed" rel="self" type="application/rss+xml" />
	<link>http://www.pixellica.com</link>
	<description>Inspiration &#38; instruction for art and design</description>
	<lastBuildDate>Sat, 10 Sep 2011 23:47:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Free WordPress Script for Custom Post Images</title>
		<link>http://www.pixellica.com/wordpress-2/free-wordpress-script-for-custom-post-images</link>
		<comments>http://www.pixellica.com/wordpress-2/free-wordpress-script-for-custom-post-images#comments</comments>
		<pubDate>Fri, 30 Oct 2009 16:21:24 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[php script]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.pixellica.com/?p=837</guid>
		<description><![CDATA[Blogs look very nice with a&#160;flashy image above each post on&#160;the&#160;index page. The&#160;problem is when a&#160;WordPress theme comes configured like this you have to&#160;use complicated pre-coded Custom Fields in&#160;each post or&#160;go without the&#160;image altogether. There’s no allowing for&#160;those times when it would be so much easier to&#160;have the&#160;index page grab the&#160;first image in&#160;the&#160;post&#160;&#8212; or&#160;even for&#160;those [...]]]></description>
			<content:encoded><![CDATA[<p class="big">Blogs look very nice with a&nbsp;flashy image above each post on&nbsp;the&nbsp;index page. The&nbsp;problem is when a&nbsp;WordPress theme comes configured like this you have to&nbsp;use complicated pre-coded Custom Fields in&nbsp;each post or&nbsp;go without the&nbsp;image altogether. There’s no allowing for&nbsp;those times when it would be so much easier to&nbsp;have the&nbsp;index page grab the&nbsp;first image in&nbsp;the&nbsp;post&nbsp;&#8212; or&nbsp;even for&nbsp;those rare times when you don’t have any image and&nbsp;just want a&nbsp;default one put up there.</p>
<p><span id="more-837"></span></p>
<p><a href="#download">Download</a> | <a href="#installing">Installing</a> | <a href="#using">Using</a> | <a href="#customizing">Customizing</a> | <a href="#filters">Filters</a></p>
<p>A&nbsp;while ago I&nbsp;was developing a&nbsp;theme for&nbsp;giving away (actually, for&nbsp;using when I&nbsp;launched Pixellica but I’ve since used a&nbsp;third-party them for&nbsp;different reasons)&nbsp;&#8212; and&nbsp;in&nbsp;the&nbsp;process of&nbsp;developing it I&nbsp;realized there was no easy way to&nbsp;solve the&nbsp;problem above. Either you are forced to&nbsp;use a&nbsp;weird Custom Field or&nbsp;hard-code some image in&nbsp;place.</p>
<p>Here&#8217;s the&nbsp;solution I&nbsp;came up with. It utilizes Darren Hoyt’s fantastic <a href="http://www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/" title="TimThumb site" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/?referer=');">Tim Thumb</a> resizing script (which I&nbsp;include in&nbsp;the&nbsp;download package, unabridged, linked and&nbsp;credited. Altogether: Darren is cool.)</p>
<p>It involves a&nbsp;simple amendment to&nbsp;the&nbsp;index page of&nbsp;your WordPress theme, and&nbsp;uploading no more than three files to&nbsp;no more than three directories. It’s very simple.</p>
<p><a name="download"></a><br />
<center><a href="/downloads/GetImage-1.0.2.zip" title="download the package" class="download"><img src="/images/downloadicon.png" height="24" width="22" alt="download" border="0" />Download the&nbsp;Package</a></center></p>
<h3>What It Does</h3>
<p>The&nbsp;function works on&nbsp;a&nbsp;three-test basis, like this:</p>
<ul class="bullet">
<li><strong>First:</strong> Check to&nbsp;see if the&nbsp;author <em>has specified a&nbsp;Custom Field image</em>. If so, it means there is a&nbsp;specific image the&nbsp;author wants to&nbsp;use, so it better use ie</li>
<li><strong>Second:</strong> If no Custom Field image is specified, then grab the&nbsp;first image from the&nbsp;post in&nbsp;question</li>
<li><strong>Third:</strong> If there are no images in&nbsp;the&nbsp;post itself, then use a&nbsp;fail-safe image already on&nbsp;the&nbsp;server (If desired. You can toggle this option off)</li>
</ul>
<p>Got that? Check for&nbsp;a&nbsp;Custom Image. If not, check for&nbsp;a&nbsp;post image. If not, use a&nbsp;default image. Simple.</p>
<p><a name="installing"></a></p>
<h3>Installing GetImage</h3>
<p>Here’s the&nbsp;script in&nbsp;all it’s beauty (a&nbsp;commented version is in&nbsp;the&nbsp;download package)</p>
<pre name="code" class="php">
function getImage($h,$w,$filter) {

$customIMG = "image-featured";

 global $post, $posts;
 ob_start();
 ob_end_clean();
 $output = preg_match_all('/<img.+src=['"]([^'"]+)['"].*>/i', $post->post_content, $matches);

 $values = get_post_custom_values($customIMG);
 $checkValues = get_post_meta($post->ID, $customIMG, true);

 $echoIMG = "images/default-image.jpg";

 if ($checkValues) {

 $echoIMG = "images/$values[0]";

 } elseif ($output) {

 $echoIMG = $matches [1] [0];

 }

 if ($filter) $filter = "&#038;f=$filter";

 return "<img src="".get_bloginfo('template_url')."/scripts/timthumb.php?src=$echoIMG&#038;h=$h&#038;w=$w&#038;zc=1&#038;$filter" alt="" height="$h" width="$w" />";

}
</pre>
<p><a name="using"></a></p>
<h3>Using GetImage</h3>
<h4>Installing</h4>
<p>Upload the&nbsp;TimThumb file to&nbsp;your theme&#8217;s &#8220;scripts&#8221; directory (create it if it doesn&#8217;t exist).</p>
<p>Upload &#8220;default-image.jpg&#8221; to&nbsp;your theme&#8217;s &#8220;images&#8221; folder (again, create it if it&#8217;s not there).</p>
<p>Open your theme&#8217;s &#8220;functions.php&#8221; file and&nbsp;paste in&nbsp;the&nbsp;contents of&nbsp;the&nbsp;&#8221;GetImage.php&#8221; file.</p>
<h4>Using</h4>
<p>Here’s the&nbsp;code you insert into your theme wherever you want the&nbsp;image to&nbsp;appear:</p>
<pre name="code" class="php">
&lt;? php echo getImage( height, width, "" );?&gt;
</pre>
<p>Replace height and&nbsp;width with the&nbsp;dimensions you want for&nbsp;the&nbsp;image. For&nbsp;example, here on&nbsp;Pixellica I&nbsp;use this function to&nbsp;display images on&nbsp;the&nbsp;index, category and&nbsp;archives pages. I&nbsp;want the&nbsp;image to&nbsp;be 250 pixels high and&nbsp;570 pixels wide. So the&nbsp;code I&nbsp;use is this:</p>
<pre name="code" class="php">
&lt;? php echo getImage(250,570,"");?&gt;
</pre>
<p>The&nbsp;function operates inside the&nbsp;WordPress loop&nbsp;&#8212; and&nbsp;grabs whatever image is attached to&nbsp;each post as&nbsp;a&nbsp;Custom Field, or, Grabs the&nbsp;first image from each respective post.</p>
<p>To&nbsp;use GetImage for&nbsp;a&nbsp;Custom Field, add a&nbsp;Custom Field on&nbsp;each post called &#8220;image-featured&#8221; and&nbsp;give it an&nbsp;absolute path to&nbsp;the&nbsp;image you want to&nbsp;use.</p>
<p><a name="customizing"></a></p>
<h3>Customizing GetImage</h3>
<h4>The&nbsp;Custom Field Name</h4>
<p>By default the&nbsp;Custom Field name for&nbsp;GetImage to&nbsp;use is “image-featured”&nbsp;&#8212; but this is easily customized. If you want to&nbsp;change the&nbsp;name of&nbsp;the&nbsp;Custom Field, go into the&nbsp;GetImage function and&nbsp;find this line:</p>
<pre name="code" class="php">
$customIMG = "image-featured";
</pre>
<p>And&nbsp;change the&nbsp;value of&nbsp;the&nbsp;variable (“image-featured”) to&nbsp;whatever you want. You can call it LateForDinner for&nbsp;all I&nbsp;care.:)</p>
<h4>Styling the&nbsp;Image</h4>
<p>GetImage attaches a&nbsp;unique class to&nbsp;each image tag in&nbsp;the&nbsp;output HTML, so you can style them specifically. The&nbsp;unique class name is</p>
<pre name="code" class="php">
featuredIMG
</pre>
<p>You can use CSS to&nbsp;do whatever you want with the&nbsp;image. I&nbsp;use it to&nbsp;apply a&nbsp;slight rounded corners effect.</p>
<p><a name="filter"></a></p>
<h3>Filters</h3>
<p>Notice there’s an&nbsp;empty string variable in&nbsp;the&nbsp;function call. This is where you can use the&nbsp;filters from the&nbsp;TimThumb script. A&nbsp;list of&nbsp;all filters can be found on&nbsp;line 30 (or&nbsp;thereabouts) in&nbsp;the&nbsp;TimThumb.php file. The&nbsp;only ones I&nbsp;use are “greyscale”, “blur” and&nbsp;“smooth” for&nbsp;which the&nbsp;codes are “2”, “8” and&nbsp;“11” respectively. So to&nbsp;make the&nbsp;image greyscale, for&nbsp;example, use this:</p>
<pre name="code" class="php">
&lt;? php echo getImage(250,570,"2");?&gt;
</pre>
<p>&#8230;and&nbsp;the&nbsp;image will be resized to&nbsp;250 pixels high by 570 pixels wide and&nbsp;display in&nbsp;black and&nbsp;white.</p>
<h3>Using the&nbsp;Function</h3>
<p>I&nbsp;don’t care who downloads the&nbsp;function. I&nbsp;would ask you don’t use it on&nbsp;any website that glorifies porn or&nbsp;violence. And&nbsp;also, it took me a&nbsp;few hours of&nbsp;my&nbsp;life to&nbsp;code and&nbsp;troubleshoot this script, so I’d appreciate it greatly if you’d leave the&nbsp;credit in&nbsp;place.</p>
<p>Does it work for&nbsp;you? Do you have any thoughts or&nbsp;suggestions, or&nbsp;even a&nbsp;way to&nbsp;make it work better? Comment and&nbsp;share your ideas!</p>
<div id="crp_related"><h4 class="related">Related Posts:</h4><ul><li><a href="http://www.pixellica.com/photoshop/photoshop-tutorial-yellowcard-moon" rel="bookmark" class="crp_title">Photoshop Tutorial: Yellowcard Moon</a></li><li><a href="http://www.pixellica.com/inspiration/focus-on-shane-devries" rel="bookmark" class="crp_title">Focus on Shane Devries</a></li><li><a href="http://www.pixellica.com/inspiration/very-cool-bird-photography-by-andrew-zuckerman" rel="bookmark" class="crp_title">Very Cool Bird Photography by Andrew Zuckerman</a></li><li><a href="http://www.pixellica.com/wallpaper/awesome-wallpaper-love-in-a-cage" rel="bookmark" class="crp_title">Awesome Wallpaper: Love In a Cage</a></li><li><a href="http://www.pixellica.com/inspiration/video-rooftop-scene-from-the-matrix-in-legos%e2%84%a2" rel="bookmark" class="crp_title">Video: Rooftop Scene from The Matrix in Legos™</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.pixellica.com/wordpress-2/free-wordpress-script-for-custom-post-images/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.pixellica.com @ 2012-02-05 01:50:57 -->
