Getting image from post but exculding some
-
For my blog I have a couple rss feeds of some of my other blogs and they are being auto posted using a plugin, I am using this solution below to grab the first image of the most recent post from that rss feed but sometimes it’ll grab the little share this on facebook image or digg this image that is tiny and then resize it and make it huge. Is there a way to make sure the image grabbed doesn’t have a certain word in it ? Hope this makes sense and is possible to do because right now the image looks terrible,
Thanks in advance Aaronfunction catch_first_image() {
02 global $post, $posts;
03 $first_img = ”;
04 ob_start();
05 ob_end_clean();
06 $output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches);
07 $first_img = $matches [1] [0];
08
09 // no image found display default image instead
10 if(!empty($first_img))
11 {
12 ?>
13
14 <?php
15 echo “<img src='”.get_bloginfo(‘template_url’).”/thumb.php?src=”.$first_img.”&w=92&h=75&zc=1′ alt=” />”;
16 ?>
17
18 <?php
19 }
20 else
21 {
22 // Your default Image
23 echo ‘<img src=”default_image.jpg” alt=””/> ‘;
24 }
25 }
- The topic ‘Getting image from post but exculding some’ is closed to new replies.