<?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>Design Tips &#187; functions</title>
	<atom:link href="http://design-tips.com/tag/functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://design-tips.com</link>
	<description>Where designers share secret tricks</description>
	<lastBuildDate>Thu, 18 Oct 2012 21:15:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>Get the first image from the post and display it in WordPress</title>
		<link>http://design-tips.com/graphic-design/get-the-first-image-from-the-post-and-display-it-in-wordpress/</link>
		<comments>http://design-tips.com/graphic-design/get-the-first-image-from-the-post-and-display-it-in-wordpress/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 12:39:39 +0000</pubDate>
		<dc:creator>mirkohumbert</dc:creator>
				<category><![CDATA[Graphic design]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://design-tips.com/?p=524</guid>
		<description><![CDATA[By default, WordPress will not take your images with the excerpt on the homepage. This is the reason why many people use the thumbnail function or custom fields to display an image for the article on the front page. However, there is a simple way to display the first image of your article on the front page with a function. For that, just add this code to the functions.php theme file function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all( '/&#60;img.+src=['"]([^'"]+)['"].*&#62;/i', $post-&#62;post_content, $matches ); $first_img = $matches[1][0]; if ( empty( $first_img ) ) { // Defines a default image $first_img = "/images/default.jpg"; } return $first_img; } Then you can call this function from within the loop &#60;?php echo catch_that_image() ?&#62;]]></description>
			<content:encoded><![CDATA[<p>By default, WordPress will not take your images with the excerpt on the homepage. This is the reason why many people use the thumbnail function or custom fields to display an image for the article on the front page.</p>
<p>However, there is a simple way to display the first image of your article on the front page with a function.</p>
<p><span id="more-524"></span></p>
<p>For that, just add this code to the <em>functions.php</em> theme file</p>
<p><code>
<pre>
function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all( '/&lt;img.+src=['"]([^'"]+)['"].*&gt;/i', $post-&gt;post_content, $matches );
  $first_img = $matches[1][0];

  if ( empty( $first_img ) ) { // Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}
</pre>
<p></code></p>
<p>Then you can call this function from within the loop</p>
<p><code>
<pre>
&lt;?php echo catch_that_image() ?&gt;
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://design-tips.com/graphic-design/get-the-first-image-from-the-post-and-display-it-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
