Get all images in post and comments like Twitter before post title

I want to know if it’s possible to get all the images that are in a post and his comments, make them a thumbnail and put it before (or in a sidebar or something) the post title to show, just like Twitter does. Of course it would be wonderful if you navigate to the comment where it was inserted if you click on a thumbnail, but that’s something for later.

Is this possible, if so, how?

Read More

PS: I am not using a plugin, I just want to know if it can search for all the <img> tags and make them thumbnails out of no where…

Related posts

1 comment

  1. Getting all the images from the post, and adding them to the top of the post is relatively easy. You can do something like this: (Note, this is just a code example. I’m not 100% what you are looking for. Hopefully this is enough to get you started.)

    function getImagesInThisPost() {
        global $post, $posts;
        //find all the <img>'s in the post
        $output = preg_match_all(
            '/<img.+src=['"]([^'"]+)['"].*>/i', 
            $post->post_content, //from the post content
            $matches
        );
    
        //loop throuhg all the images we found, and put them on the page
        foreach($matches[1] as $single){
            echo "<img src="{$single}">";
        } 
    }
    

Comments are closed.