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

  1. scottnath
    Posted 3 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 );
    	                // use the post-thumbnail
    	                preg_match_all('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'>]*)/i', $postthumbnail, $matches);
    	                // 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.



Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Calendar Archives
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic