WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: WordPress Popular Posts] Choose your own thumbnails (5 posts)

  1. masterbassie
    Member
    Posted 4 years ago #

    is there any way to choose your own thumbnails or have the code search for a specific tag in the image so that it only accepts that image as a thumbnail?

    additionally the plugin seems to search only in the content of the post (which is the most likely place) but i have a couple pages which use separate templates with images that are useful which are technically not in the content section...

    thanks

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

  2. Héctor Cabrera
    Member
    Posted 4 years ago #

    For the time being, my plugin uses the very first image it finds in your posts to create its thumbnail. There is, however, a small hack you can use!

    If you know how to use custom fields, this hack can be of help:

    Using a text editor of your choice, open wordpress-popular-posts.php and around line 244 you'll find this code:

    if ($this->options_holder[$summoner]['thumbnail']['show'] ) {
          // let's try to retrieve the first image of the current post
          $img = $this->get_img($wppost->ID);
          if ( (!$img || empty($img)) || !$this->GD ) {
           $thumb = "";
          } else {
           $thumb = "<a href=\"".get_permalink($wppost->ID)."\" title=\"". htmlspecialchars(stripslashes($tit)) ."\"><img src=\"". get_bloginfo('url') . "/" . PLUGINDIR . "/wordpress-popular-posts/scripts/timthumb.php?src=". $img[1] ."&h=".$this->options_holder[$summoner]['thumbnail']['height']."&w=".$this->options_holder[$summoner]['thumbnail']['width']."&zc=1\" alt=\"".$wppost->post_title."\" border=\"0\" class=\"wpp-thumbnail\" "."/></a>";
          }
    
         }

    ... change it to:

    if ($this->options_holder[$summoner]['thumbnail']['show'] ) {
          // let's try to retrieve the first image of the current post
          $img = get_post_meta($wppost->ID, 'key_1', true);
          if (empty($img)) {
           $thumb = "";
          } else {
           $thumb = "<a href=\"".get_permalink($wppost->ID)."\" title=\"". htmlspecialchars(stripslashes($tit)) ."\"><img src=\"".$img."\" alt=\"".$wppost->post_title."\" border=\"0\" class=\"wpp-thumbnail\" "."/></a>";
          }
    
         }

    ... where 'key_1' ( get_post_meta($wppost->ID, 'key_1', true); ) is the name of the custom field that stores the path to the image you want to use.

    Give it a try and let me know the results.

  3. masterbassie
    Member
    Posted 4 years ago #

    that didn't work for me or rather that only looks for the custom field img and not the first image. so i piecemealed it together to form the code below. It's not very pretty but it works. I also included a default picture if no pic is available.

    if ($this->options_holder[$summoner]['thumbnail']['show'] ) {
           // let's try to retrieve the first image of the current post
          $imgdirectory = get_bloginfo('template_directory') .'/images';
          $customimg = get_post_meta($wppost->ID, 'Image', true);
           if ($customimg != '') {
            $img = $imgdirectory .'/lessons/' . $customimg;
            $thumb = "<a href=\"".get_permalink($wppost->ID)."\" title=\"". htmlspecialchars(stripslashes($tit)) ."\"><img src=\"". get_bloginfo('url') . "/" . PLUGINDIR . "/wordpress-popular-posts/scripts/timthumb.php?src=". $img ."&h=".$this->options_holder[$summoner]['thumbnail']['height']."&w=".$this->options_holder[$summoner]['thumbnail']['width']."&zc=1\" alt=\"".$wppost->post_title."\" border=\"0\" class=\"wpp-thumbnail\" "."/></a>";
    } else {
          $img = $this->get_img($wppost->ID);
          if ( (!$img || empty($img)) || !$this->GD ) {
           $thumb = "<a href=\"".get_permalink($wppost->ID)."\" title=\"". htmlspecialchars(stripslashes($tit)) ."\"><img src=\"". get_bloginfo('url') . "/" . PLUGINDIR . "/wordpress-popular-posts/scripts/timthumb.php?src=". $imgdirectory ."/ils-small-square.png&h=".$this->options_holder[$summoner]['thumbnail']['height']."&w=".$this->options_holder[$summoner]['thumbnail']['width']."&zc=1\" alt=\"".$wppost->post_title."\" border=\"0\" class=\"wpp-thumbnail\" "."/></a>";
          } else {
           $thumb = "<a href=\"".get_permalink($wppost->ID)."\" title=\"". htmlspecialchars(stripslashes($tit)) ."\"><img src=\"". get_bloginfo('url') . "/" . PLUGINDIR . "/wordpress-popular-posts/scripts/timthumb.php?src=". $img[1] ."&h=".$this->options_holder[$summoner]['thumbnail']['height']."&w=".$this->options_holder[$summoner]['thumbnail']['width']."&zc=1\" alt=\"".$wppost->post_title."\" border=\"0\" class=\"wpp-thumbnail\" "."/></a>";
          }
    
         }
    }

    Another problem i found is that a post (which has no other images) with an embedded imeem player is mistaken as an image and then returned as a thumbnail. is there any code to extract only the common image files: jpg, png, gif?

    thanks for your help

  4. Héctor Cabrera
    Member
    Posted 4 years ago #

    Well, my plugin looks for <img /> tags in your content via pregmatch. It should be simple to filter out those images that are not jpg, png, etc.

    I don't know the imeem player, how does it work exactly? Is it a flash object?

  5. masterbassie
    Member
    Posted 4 years ago #

    you can see it here
    http://www.ilivesalsa.com/salsa/salsa-music/the-styles-of-salsa-music/

    its an embedded flash music player from imeem.com the music sharing service.

Topic Closed

This topic has been closed to new replies.

About this Topic