how to retrieve first image as thumb - wordpress

Discussion in 'Blogging' started by mixtaka, Jul 9, 2010.

  1. #1
    how to retrieve first image as thumb from the post in wordpress.

    now im using the code, which is successfully work, but the thumb will be crop not resize. can anyone tell me how can resize thumb not crop by modification the code.

    i add this code in funtion.php

    // Retrieve the src of first image in a post
    function bm_extract_string($start, $end, $original) {
    $original = stristr($original, $start);
    $trimmed = stristr($original, $end);
    return substr($original, strlen($start), -strlen($trimmed));
    }
    function getFirstImage() {
    $content = get_the_content();
    $pic_string = bm_extract_string('src="','" ',$content);
    $imagesize = getimagesize($pic_string);
    list($width, $height, $type, $attr) = getimagesize($pic_string);
    $link = get_permalink();
    $title = get_the_title($post->post_title);
    echo '<a href="'.$link.'" style="background:url('.$pic_string.'); display:block; width:100px; height:150px;" title="'.$title.'"></a>';
    }
    Code (markup):
    and than this code in the template like - search result, archive, index etc


     
    Last edited: Jul 9, 2010
    mixtaka, Jul 9, 2010 IP
  2. hadie87

    hadie87 Guest

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i not really know how to solve your problem.
    But, i have been use this scirpt to resize image
    <?php $postimageurl = get_post_meta($post->ID, 'post-img', true); if ($postimageurl) { ?>
                        <div class="pic fl">
                          <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php echo $postimageurl; ?>" alt="Post Pic" width="200" height="200" /></a>
                        </div>
    					<?php } ?>
    					<div class="post-title">
    						<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    					</div>
    Code (markup):
    Example:
    _http://wptheme.dankerizer.net
     
    hadie87, Jul 9, 2010 IP
  3. mixtaka

    mixtaka Active Member

    Messages:
    267
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    where i use this script
     
    mixtaka, Jul 9, 2010 IP
  4. hadie87

    hadie87 Guest

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you can put that script AFRTER this scipt :
    	<div class="box post" id="post-<?php the_ID(); ?>">
    				<div class="content">
    Code (markup):
    add my Yahoo messenger :hadie_alone
    and i will help you for free :D
     
    hadie87, Jul 9, 2010 IP