WordPress.org

Ready to get started?Download WordPress

Forums

Calendar Archives
[resolved] Modified: using Post-Thumbnail first if it exists. (1 post)

  1. scottnath
    Member
    Posted 2 years ago #

    Hi there,

    Because I use WordPress' post-thumbnails feature I've already chosen the image that I would like to represent a given post. Because of that, I made a modification to your code to first check if there is a post-thumbnail, and if not, to then choose an image from the post. It'd be great to have something along these lines in a future release.

    // Check if there is a post-thumbnail
                    $postthumbnail = get_the_post_thumbnail( $posts[$index]->ID );
                    if($postthumbnail){
    	                // use the post-thumbnail
    	                preg_match_all('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'>]*)/i', $postthumbnail, $matches);
                    }else{
    	                // Get all images from post's body
    	                preg_match_all('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'>]*)/i', $posts[$index]->post_content, $matches);
                    }

    Thanks for writing this, exactly what I was looking for.

    -scott

    http://wordpress.org/extend/plugins/calendar-archives/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic