First image (external) in "popular post"
-
Hi.
I have the popular post and I want add also an image.
I use this script to capture first image from a post:
function get_first_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output_img = 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; }I want add the function “first_image” into this script:
if ($output) { foreach ($output as $line) { $hits = ($instance['show_hits']) ? ' ('.(int)$line->meta_value.')' : ''; $out .= ' <a title="'.str_replace("'","'", $line->post_title).'" href="'.get_permalink($line->ID).'">'.$line->post_title.'</a> <span class="most_and_least_read_posts_hits">'.$hits.'</span></div><!-- fine top_post -->'; } } else { $out .= ''.__('No results available', 'least_read_posts'); } return $out; }
The topic ‘First image (external) in "popular post"’ is closed to new replies.