I'm having a small issue with wordpress; what i want to achieve is move my first image on a blog post to the top of the div, and the content somewhere else. My current script looks like this:
$recent_posts = wp_get_recent_posts($args);
foreach( $recent_posts as $recent ){
$author = get_the_author();
echo '<div class="col-md-4 col-lg-4 blog" ><div class="inner">';
preg_match_all("/(<img [^>]*>)/",$recent["post_content"],$img,PREG_PATTERN_ORDER);
echo $img[1][0];
echo '<h3><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"].'</a></h3> ';
echo '<h6>' . $author . '</h6>';
preg_match_all("/<p>(.*?)<\/p>/s",$recent["post_content"],$content,PREG_PATTERN_ORDER);
echo '<p>';
echo $content[1][0];
echo '</p>';
echo '</div>';
echo '</div>;
}
Instead i would like to use one preg_match_all, 1st array would select my whole first img tag and the 2nd array would select all the text after that. How can i achieve this result?
My current output from $recent["post_content"] is :
<img src="">
<p>my content</p>
What my desired output would be is:
<img src="">
$title
$author
<p>my content</p>
Kind regards.