<?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>SofaRider &#187; wordpress title image</title>
	<atom:link href="http://rider.sofarider.com/tag/wordpress-title-image/feed/" rel="self" type="application/rss+xml" />
	<link>http://rider.sofarider.com</link>
	<description>WordPress Themes, Widgets, Development &#124; WEB &#38; Graphic Design</description>
	<lastBuildDate>Wed, 14 Oct 2009 08:40:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to add teaser image next to post title</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/how-to-add-an-image-teaser-next-to-post-title/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/how-to-add-an-image-teaser-next-to-post-title/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 06:52:11 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[extract image]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[teaser image]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[wordpress title image]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=245</guid>
		<description><![CDATA[Recently I&#8217;ve received an email regarding those little thumbnails next to Post title. My mate asked me to explain how to set it up so here&#8217;s the &#8216;trick&#8217;. As you may note, teaser thumb in this Post will only be displayed once. There&#8217;s no duplicate within the content in spite of the fact that you [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/07/gorilla-200x200.jpg" alt="gorilla" title="gorilla" width="200" height="200" class="alignnone size-thumbnail wp-image-246" />Recently I&#8217;ve received an email regarding those little thumbnails next to Post title. My mate asked me to explain how to set it up so here&#8217;s the &#8216;trick&#8217;. As you may note, teaser thumb in this Post will only be displayed once. There&#8217;s no duplicate within the content in spite of the fact that you upload teaser image along with the rest of the content and all other images related to it. Yes, no Custom Fields involved here at all!</p>
<blockquote><p>Otherwise spoken, how to extract certain image out of the post and display it out of context.</p></blockquote>
<p>So how the hell WordPress can know which image is supposed to represent teaser image if there&#8217;s at least one image extra attached to the very same Post? Well, that&#8217;s the trick. <strong>We must use different &#8220;insert&#8221; method</strong>. Let&#8217;s assume all other images are clickable and users are able to see full size for each of them. In order to properly extract teaser image from Post later in frontend we&#8217;ll use the following method to insert it first:<br />
<a href="http://rider.sofarider.com/wp-content/uploads/2009/07/ill_post.png" rel="shadowbox[post-245];player=img;"><img src="http://rider.sofarider.com/wp-content/uploads/2009/07/ill_post.png" alt="ill_post" title="ill_post" width="588" height="343" class="alignnone size-full wp-image-248" /></a><br />
If you take a look at the HTML code after, you&#8217;ll note that this image is not enclosed with &lt;a&gt;&lt;/a&gt; tags, right? Let&#8217;s now take a look how to extract such image from the content&#8230;</p>
<h2>Extracting teaser image from Post</h2>
<p>The basic idea is to grab teaser thumbnail from the_content() and replace it with &#8211; nothing, empty string. Remember, we don&#8217;t want to have the same image displayed twice within Post.</p>
<pre>
<code>
&lt;?php
    // get the first image out of content, prevent double image display
    $path = &quot;&quot;; // teaser image path
    $content = get_the_content(); // get Post content entirely
    // grab fist image (teaser thumb) by pattern
    $frst_image = preg_match_all( '|&lt;img.*?src=[\'&quot;](.*?)[\'&quot;].*?&gt;|i', $content, $matches );
    // any image there?
    if( $frst_image &gt; 0 ) {
    	$path = $matches[ 1 ][ 0 ]; // we need the first one only!
    	// replace with empty string in order to avoid duplicates
    	$content = preg_replace( '|&lt;img.*?src=[\'&quot;](' . $path . ')[\'&quot;].*?&gt;|i', '', $content );
    }
    if( $path ) {
    	// teaser image found! display it now or leave in variable for later
?&gt;
    	&lt;img src=&quot;&lt;?php echo $path; ?&gt;&quot; alt=&quot;&lt;?php echo get_the_title(); ?&gt;&quot; class=&quot;thumbnail&quot; /&gt;
&lt;?php
    	$path = &quot;&quot;;
    } else {
    	// teaser image not found. replace with dummy graphic
?&gt;
    	&lt;img src=&quot;&lt;?php echo bloginfo( 'template_directory' ) . ( '/images/no_image.jpg' ); ?&gt;&quot; alt=&quot;&lt;?php echo get_the_title(); ?&gt;&quot; class=&quot;thumbnail&quot; /&gt;
&lt;?php
    	$path = &quot;&quot;;
    }
?&gt;
</code>
</pre>
<p>There&#8217;s one little tip at the end: Insert teaser images before any other Post content (text or other images). It&#8217;s good idea to keep things organized.</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/how-to-add-an-image-teaser-next-to-post-title/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
