wordpress | January 26th, 2021

How to get thumb image from post

Add this function to function.php file

function getImage($num) {
global $more;
$more = 1;
$link = get_permalink();
$content = get_the_content();
$count = substr_count($content, ‘
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, ”);
$postOutput = substr($post, 0, $imgEnd+1);
$postOutput = preg_replace(’/width=”([0-9]*)” height=”([0-9]*)”/’, ‘/width=”117″ height=”68″/’,$postOutput);
$postOutput = preg_replace(’/alignright/’, ‘alignleft’,$postOutput);

$image[$i] = $postOutput;
$start=$imgEnd+1;
}
if(stristr($image[$num],’‘.$image[$num].”“; }
$more = 0;
}

and call it as where you want to show image   .. inside loop.

One comment

    Trackbacks and Pingbacks

    1. CHAD

    Leave a Comment