<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Extract Images from wordpress post / Page</title>
	<atom:link href="http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/</link>
	<description>PHP,Wordpress,Jquery Expert</description>
	<lastBuildDate>Thu, 02 Feb 2012 10:57:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: mike</title>
		<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/comment-page-1/#comment-4315</link>
		<dc:creator>mike</dc:creator>
		<pubDate>Fri, 17 Jun 2011 23:12:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=90#comment-4315</guid>
		<description>I amended this to also extract the image caption and post it in a span just after the image, quite useful for making portfolio type sites. Thanks for the original code, I can claim very little credit!


function extract_post_images( $post, $w, $h ) {
	$posttext = $post-&gt;post_content;
	$posttext1 = $post-&gt;post_content;
	 
	$regular_expression = &#039;~src=&quot;[^&quot;]*&quot;~&#039;;
	$regular_expression1 = &#039;~]*\ /&gt;~&#039;;
	$regular_expression3 = &#039;~caption=&quot;[^&quot;]*&quot;~&#039;;	
	
	preg_match_all( $regular_expression3, $posttext, $allcaptions );
	preg_match_all( $regular_expression, $posttext, $allpics );
	 
	$NumberOfPics = count($allpics[0]);
	 
	if ( $NumberOfPics &gt; 0 ) {	 
		for ( $i=0; $i &lt; $NumberOfPics ; $i++ ) {
			// hack the img url about
			$str1=$allpics[0][$i];
			$str1=trim($str1);
			$len=strlen($str1);
			$imgpath=substr_replace(substr($str1,5,$len),&quot;&quot;,-1);

			// hack the image caption about
			$str2=$allcaptions[0][$i];
			$str2=trim($str2);
			$len2=strlen($str2);	
			$caption=substr_replace(substr($str2,9,$len2),&quot;&quot;,-1);

			echo &#039;&#039;;
			echo &#039;	&#039;.$caption.&#039;&#039;;
			echo &#039;&#039;;
		}
	}
}</description>
		<content:encoded><![CDATA[<p>I amended this to also extract the image caption and post it in a span just after the image, quite useful for making portfolio type sites. Thanks for the original code, I can claim very little credit!</p>
<p>function extract_post_images( $post, $w, $h ) {<br />
	$posttext = $post-&gt;post_content;<br />
	$posttext1 = $post-&gt;post_content;</p>
<p>	$regular_expression = &#8216;~src=&#8221;[^"]*&#8221;~&#8217;;<br />
	$regular_expression1 = &#8216;~]*\ /&gt;~&#8217;;<br />
	$regular_expression3 = &#8216;~caption=&#8221;[^"]*&#8221;~&#8217;;	</p>
<p>	preg_match_all( $regular_expression3, $posttext, $allcaptions );<br />
	preg_match_all( $regular_expression, $posttext, $allpics );</p>
<p>	$NumberOfPics = count($allpics[0]);</p>
<p>	if ( $NumberOfPics &gt; 0 ) {<br />
		for ( $i=0; $i &lt; $NumberOfPics ; $i++ ) {<br />
			// hack the img url about<br />
			$str1=$allpics[0][$i];<br />
			$str1=trim($str1);<br />
			$len=strlen($str1);<br />
			$imgpath=substr_replace(substr($str1,5,$len),&quot;&quot;,-1);</p>
<p>			// hack the image caption about<br />
			$str2=$allcaptions[0][$i];<br />
			$str2=trim($str2);<br />
			$len2=strlen($str2);<br />
			$caption=substr_replace(substr($str2,9,$len2),&quot;&quot;,-1);</p>
<p>			echo &#039;&#8217;;<br />
			echo &#8216;	&#8216;.$caption.&#8221;;<br />
			echo &#8221;;<br />
		}<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jimi</title>
		<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/comment-page-1/#comment-3997</link>
		<dc:creator>Jimi</dc:creator>
		<pubDate>Mon, 11 Apr 2011 22:02:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=90#comment-3997</guid>
		<description>I&#039;m appending this code in TDO mini form to get the first image in the attachment. Only problem is that is grabbing all the images from all posts and placing them, can You please tell me how to do this but to take only the first image from the post and nothing else. Cheers friend.

code I&#039;m using currently:

 get_the_ID(), &#039;post_type&#039; =&gt; &#039;attachment&#039;, &#039;post_mime_type&#039; =&gt; &#039;image&#039;) );
foreach ( $attachments as $attachment_id =&gt; $attachment ) {
echo &#039;&#039;;
echo &#039; &#039; . wp_get_attachment_link( $attachment_id ) . &#039;&#039;;
echo &#039;&#039;;
} ?&gt;</description>
		<content:encoded><![CDATA[<p>I&#8217;m appending this code in TDO mini form to get the first image in the attachment. Only problem is that is grabbing all the images from all posts and placing them, can You please tell me how to do this but to take only the first image from the post and nothing else. Cheers friend.</p>
<p>code I&#8217;m using currently:</p>
<p> get_the_ID(), &#8216;post_type&#8217; =&gt; &#8216;attachment&#8217;, &#8216;post_mime_type&#8217; =&gt; &#8216;image&#8217;) );<br />
foreach ( $attachments as $attachment_id =&gt; $attachment ) {<br />
echo &#8221;;<br />
echo &#8216; &#8216; . wp_get_attachment_link( $attachment_id ) . &#8221;;<br />
echo &#8221;;<br />
} ?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: M de Wit</title>
		<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/comment-page-1/#comment-3428</link>
		<dc:creator>M de Wit</dc:creator>
		<pubDate>Sat, 05 Mar 2011 14:09:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=90#comment-3428</guid>
		<description>That&#039;s correct! Do you have a solution for this?
cheers, Mattijs</description>
		<content:encoded><![CDATA[<p>That&#8217;s correct! Do you have a solution for this?<br />
cheers, Mattijs</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: snilesh</title>
		<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/comment-page-1/#comment-3423</link>
		<dc:creator>snilesh</dc:creator>
		<pubDate>Sat, 05 Mar 2011 12:40:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=90#comment-3423</guid>
		<description>so you want each and every image from the content section will be cropped with same size using timthumb?</description>
		<content:encoded><![CDATA[<p>so you want each and every image from the content section will be cropped with same size using timthumb?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: M de Wit</title>
		<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/comment-page-1/#comment-3405</link>
		<dc:creator>M de Wit</dc:creator>
		<pubDate>Thu, 03 Mar 2011 23:18:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=90#comment-3405</guid>
		<description>Hi Snilesh,
The code of:
&quot;Extracting Images from the Page / Post  content&quot; almost does what I would like to achieve.
The only difference is; I would like to replace the IMG src with the timthumb code and put it back in the content where it came from.
So not extracting it but alter it.
Any ideas?
Thanks,
Mattijs</description>
		<content:encoded><![CDATA[<p>Hi Snilesh,<br />
The code of:<br />
&#8220;Extracting Images from the Page / Post  content&#8221; almost does what I would like to achieve.<br />
The only difference is; I would like to replace the IMG src with the timthumb code and put it back in the content where it came from.<br />
So not extracting it but alter it.<br />
Any ideas?<br />
Thanks,<br />
Mattijs</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: snilesh</title>
		<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/comment-page-1/#comment-1309</link>
		<dc:creator>snilesh</dc:creator>
		<pubDate>Fri, 17 Sep 2010 16:49:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=90#comment-1309</guid>
		<description>Yes just let me know what you want youtube video code? like http://www.youtube.com/watch?v=5wck-tp19-A in this the video code is 5wck-tp19-A. Wordpress  added new feature where if you enter this video url in editor  code is automatically added to it. just let me know what you want just first video code or full url of the video?</description>
		<content:encoded><![CDATA[<p>Yes just let me know what you want youtube video code? like <a href="http://www.youtube.com/watch?v=5wck-tp19-A">http://www.youtube.com/watch?v=5wck-tp19-A</a> in this the video code is 5wck-tp19-A. WordPress  added new feature where if you enter this video url in editor  code is automatically added to it. just let me know what you want just first video code or full url of the video?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tarmijn</title>
		<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/comment-page-1/#comment-1308</link>
		<dc:creator>tarmijn</dc:creator>
		<pubDate>Fri, 17 Sep 2010 14:07:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=90#comment-1308</guid>
		<description>Thanks for the tutorial, do you have any idea how I can extract not an image, but an YouTube video for example. I changed img in object, but it doesn&#039;t work..</description>
		<content:encoded><![CDATA[<p>Thanks for the tutorial, do you have any idea how I can extract not an image, but an YouTube video for example. I changed img in object, but it doesn&#8217;t work..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: snilesh</title>
		<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/comment-page-1/#comment-1234</link>
		<dc:creator>snilesh</dc:creator>
		<pubDate>Fri, 27 Aug 2010 15:56:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=90#comment-1234</guid>
		<description>hi Dick,

It is very old article. Yes the text get messes up. From wordpress 2.9 new feature is added to the wordpress. the_post_thumbnail() which you can use add the thumbnail to your post. you can check more details about it at &lt;a href=&quot;http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/&quot;&gt;Wordpress 2.9 the post thumbnail&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>hi Dick,</p>
<p>It is very old article. Yes the text get messes up. From wordpress 2.9 new feature is added to the wordpress. the_post_thumbnail() which you can use add the thumbnail to your post. you can check more details about it at <a href="http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/">WordPress 2.9 the post thumbnail</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dick</title>
		<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/comment-page-1/#comment-1228</link>
		<dc:creator>Dick</dc:creator>
		<pubDate>Wed, 25 Aug 2010 15:08:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=90#comment-1228</guid>
		<description>Thanks for the nice tut. One problem though: using this in wordpress, it strips my article completely from all  tags and so on. This completely messes up the styling. Any thoughts on that? Would be great!</description>
		<content:encoded><![CDATA[<p>Thanks for the nice tut. One problem though: using this in wordpress, it strips my article completely from all  tags and so on. This completely messes up the styling. Any thoughts on that? Would be great!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miralys</title>
		<link>http://www.snilesh.com/resources/wordpress/extract-images-from-wordpress-post/comment-page-1/#comment-1074</link>
		<dc:creator>Miralys</dc:creator>
		<pubDate>Tue, 03 Aug 2010 14:35:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.snilesh.com/?p=90#comment-1074</guid>
		<description>In my Blogpost I want to display Image, Title, Text in exactly that order. So I managed to extract the image from the post and display it at the start (using your very helpful code), but it only works if the image is attached to the post. In that case, however, the image is displayed again under the article. Is there also a way to just display the text of the article, without the attached picture?</description>
		<content:encoded><![CDATA[<p>In my Blogpost I want to display Image, Title, Text in exactly that order. So I managed to extract the image from the post and display it at the start (using your very helpful code), but it only works if the image is attached to the post. In that case, however, the image is displayed again under the article. Is there also a way to just display the text of the article, without the attached picture?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

