phpwordpresswordpress-themingwordpress-thesis-theme

Wordpress Feautured Thumbnail Image Linking Gone wrong


What have I done wrong? The image does not list at all like there are no images in the media library and when I change the id, it lists all the images but I need only one. Can you help me out?

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <div class="post-masonry col-md-4 col-sm-6 wow fadeInUp ">    
        <div class="blog-wrapper" <?php echo post_class(); ?> >    
        <?php $featuredImage = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium' );  ?>    
             <img src="<?php echo $featuredImage[0]; ?>" class="img-responsive">
             <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
             <small><?php the_time('F jS, Y'); ?></small>
             <p><?php the_excerpt(); ?></p>
         </div>
    </div>
<?php endwhile; else: ?>
    <h3>No posts in database </h3>
<?php endif; ?>

I've tried so far all the possible functions: wp_get_attachment_url, wp_get_attachment_image, wp_get_attachment_image_src, wp_get_attachment...


Solution

  • Well, I managed to get what I wanted but I still haven't figure it out why it doesn't show images using those functions...

    Here is a custom function that selects the first image inside the post...

    function catch_that_image() {
        global $post, $posts;
        $first_img = "get_stylesheet_directory_uri().";
        ob_start();
        ob_end_clean();
        $output = 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 = '';
    }
        return $first_img;
    }