How to: Get the first image from the next and previous post in single.php?
-
I know I can call the function following:
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.jpg”;
}
return $first_img;
}But I try to using this function in single.php or posting page. It was display only image at own ID.
However, I need to call an image from next and previous post of this ID.
Can I do it?
Thanks!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to: Get the first image from the next and previous post in single.php?’ is closed to new replies.