maxxis
Forum Replies Created
-
Forum: Plugins
In reply to: Modifying the "catch_that_image()" function to pull a random image.Please please please help…. ??
This is the function:
——————————-[code moderated according to forum rules - please use the pastebin]
***********************************************************
Instead of the first image from every post, I just need the function to pull up a random image from every post... WP / PHP experts please help me. I have already spent two full days trying to do something, and nothing worked.
Forum: Fixing WordPress
In reply to: Help please ! – Modifying the "catch_that_image()" function.Please please please help…. ??
This is the function:
——————————-function catch_that_image() {
global $post, $posts;
$first_img = ”;
ob_start();
ob_end_clean();
$output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches);
$first_img = $matches [1] [0];if(empty($first_img)){ //Defines a default image
$first_img = “images/default.gif”;
}
return $first_img;
}And this is how I am calling it….
—————————————–
<?php if(catch_that_image()) {
echo ‘<img src=”‘ .get_stylesheet_directory_uri(). ‘/timthumb.php?src=’ .urlencode(catch_that_image()). ‘&h=63&w=84&zc=1&q=90″ style=”float: left; padding:10px 9px 0px 5px;” >‘; } ?><?php the_excerpt(‘Read on…;’); ?>
</div>
<span class=”btn-readon”>” rel=”bookmark” title=”<?php the_title(); ?>”>Read On</span></div>
<?php endwhile; ?>
<br clear=”all” />
<?php else: ?>
<!– Error message when no post published –>
<?php endif; ?>
***********************************************************
Instead of the first image from every post, I just need the function to pull up a random image from every post… WP / PHP experts please help me. I have already spent two full days trying to do something, and nothing worked.