Browse » Home » Blogging | Tips and Trick »Create WordPress Thumbnail Without Custom Field

Create WordPress Thumbnail Without Custom Field

[thebestsolver.com] How to create thumbnail image post in wordpress ? there are many ways to make thumbnail post image in wordpress, but the discussion this time I will present how to create auto thumbnail wordpress without custom field !

  1. Get the TimThumb.php Script
    Download timthumb.php script and upload in your theme
  2. Edit Functions.php
    Open your theme’s functions.php file and copy paste the code below into it.
  3. <?php
    // retreives image from the post
    function getImage($num) {
    global $more;
    $more = 1;
    $content = get_the_content();
    $count = substr_count($content, '<img');
    $start = 0;
    for($i=1;$i<=$count;$i++) {
    $imgBeg = strpos($content, '<img', $start);
    $post = substr($content, $imgBeg);
    $imgEnd = strpos($post, '>');
    $postOutput = substr($post, 0, $imgEnd+1);
    $image[$i] = $postOutput;
    $start=$imgEnd+1;
    
    $cleanF = strpos($image[$num],'src="')+5;
    $cleanB = strpos($image[$num],'"',$cleanF)-$cleanF;
    $imgThumb = substr($image[$num],$cleanF,$cleanB);
    
    }
    if(stristr($image[$num],'<img')) { echo $imgThumb; }
    $more = 0;
    }
    //retreive image ends
    ?>
  4. Open main index.php your theme and insert the code to call the code, in this tutorial we’ll paste this code above the_excerpt(); or the_content(); in index.php or home.php file.
    <div>
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php getImage('1'); ?>&w=150&h=150&zc=1">
    </a>
    </div>
  5. Add some CSS Rules
    You can style the thumbnail in any way you like, for example, you might add the following to your style.css file:

    .thumbnail a:link, .thumbnail a:visited {display:block; float:left; padding:5px; background:#e2e2e2; width:150px; height:150px; margin:5px 5px 0 0;}
    .thumbnail a:hover, .thumbnail a:active {background:#C4C4C4;}
Related Posts Plugin for WordPress, Blogger...keywords : timthumb Could not open the lockfile for writing an imagetimthumb Could not get a lock for writingCould not open the lockfile for writing an image wordpresswordpress Could not open the lockfile for writing an imagecould not get a lock for writing fix
Rating: 5» 99% like it» Reviewed by Best Solver on In Create WordPress Thumbnail Without Custom Field

Leave a Reply