function mm_posts() {
$result = '';
if ( have_posts() ) :
query_posts('cat=5&posts_per_page=4');
while ( have_posts() ) : the_post();
$post_thumbnail_id = get_post_thumbnail_id();
$post_thumbnail_url = wp_get_attachment_image_src( $post_thumbnail_id, array(300, 200) );
function mega_thmb() {
if ( has_post_thumbnail() ) :
$img = '<img src="' . $post_thumbnail_url[0] . '" alt="" class="img-responsive">';
else :
$img = '<img src="' . get_template_directory_uri() . '/img/no-image.gif" alt="" class="img-responsive">';
endif;
return $img;
}
$result .= '
<div class="col-md-3">' .
mega_thmb() .
'<div>Sport</div>
<div>Lorem ipsum dolor sit amet</div>
</div>';
endwhile;
wp_reset_query();
endif;
return $result;
}
Php displays error : Fatal error: Cannot redeclare mega_thmb() (previously declared in ...
What should I do? How write function inside the loop?