WordPress.org

Ready to get started?Download WordPress

Forums

Help displaying first image of a post as thumbnail. :) (1 post)

  1. robralston2011
    Member
    Posted 3 years ago #

    Hey guys,

    Thanks for checking this out, hope you can all help.
    I'm currently setting up a new theme that can use post by email,
    I have used some php from http://www.wprecipes.com to grab the posts first image and then grab the thumbnail of that image.

    Now that all works great, but I need to check two things.

    If there is no image in the post(only a video for example)I need the script to grab the posts featured image which gets created by video thumbnail plugin.

    so the code is below:

    <?php

    function catch_that_image() {
    global $post, $posts;
    $first_img = '';
    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))
    {
    $first_img = '' ;
    /////////// I THINK I NEED TO PUT SOMETHING IN HERE TO GRAD THE FEATURE IMAGE???? ///////////
    }else{

    $explodepoint = explode(".",$first_img);
    $count = count($explodepoint);
    $size = "-230x200";
    $explodepoint[$count-2]= $explodepoint[$count-2]."".$size;
    $thumb_img = implode(".",$explodepoint);
    echo $thumb_img;
    }
    }

    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by robralston2011
  • This topic is not resolved
  • WordPress version: 3.1.2