• Guys i am using the following code

    <?php
    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
      the_post_thumbnail(array(100,100), array('class' => 'alignleft'));
    }
    ?>

    To display the theme’s thumbnail, however it only fetches post that has featured image, how do i retrieve thumbnail for a post that has a image attachment.

    Here is the link http://n1bar.com/category/blog

Viewing 3 replies - 1 through 3 (of 3 total)
  • this is the function

    function main_image() {
    $files = get_children('post_parent='.get_the_ID().'&post_type=attachment
    &post_mime_type=image&order=desc');
      if($files) :
        $keys = array_reverse(array_keys($files));
        $j=0;
        $num = $keys[$j];
        $image=wp_get_attachment_image($num, 'large', true);
        $imagepieces = explode('"', $image);
        $imagepath = $imagepieces[1];
        $main=wp_get_attachment_url($num);
    		$template=get_template_directory();
    		$the_title=get_the_title();
        print "<img src='$main' alt='$the_title' class='frame' />";
      endif;
    }

    this is the tmeplate tag

    <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) {
      echo get_the_post_thumbnail($post->ID);
    
    } else if (  (function_exists('main_image')) && (main_image())  ) {
    
    echo main_image();
    ?>
    
    <?php } ?>

    but you may have to use css to size the post image. In twentyten I used

    .frame
    {
    width: 25%;
    }

    I’ve yet to find a way to code the size.

    looks like you got it?

    Thread Starter www.n1bar.com

    (@wwwn1barcom)

    I gave up and just added a featured image instead.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Fetch post thumbnail or attachment’ is closed to new replies.