• Resolved defyogo

    (@defyogo)


    Am using 2 wpp widgets on my sidebar. The first one uses the thumbnail from the default source that has been set on thumbnail source option. Second widget is for apps download. And here is the problem, for the second widget, i want to use thumbnail icon that found on “the first image on post”, different from the default one. Can i do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi there!

    Sorry for the late reply. Last week was been a hectic one.

    No, currently there is no configurable option to have a specific widget use a different thumbnail source.

    Here’s a workaround:

    1. Go to Settings > WordPress Popular Posts > Tools.
    2. Under Thumbnails, set Pick image from to First image on post and hit the Apply button below to shave changes.
    3. Add the following code to your theme’s functions.php file:
      <?php
      
      function my_custom_single_popular_post( $post_html, $p, $instance ){
      
          if (
              isset( $instance['widget_id'] ) 
              && 'wpp-7' == $instance['widget_id'] /* CHANGE THIS ID TO YOUR OWN! */
          ) {
      
              $post_thumbnail = get_the_post_thumbnail( $p->id, array(75, 75), array('class' => 'wpp-thumbnail featured-image') );
              $post_permalink = get_the_permalink( $p->id );
      
              $output = '<li>' . $post_thumbnail . '<a href="' . $post_permalink . '" title="' . esc_attr( $p->title ) . '">' . $p->title . '</a></li>';
      
              return $output;
      
          }
      
          // ELSE
          // Return original output
          return $post_html;
      
      }
      add_filter( 'wpp_post', 'my_custom_single_popular_post', 10, 3 );
      
      ?>
    4. From the code above, you’ll need to change the ‘wpp-7’ ID string in the IF statement to the one WordPress assigned to your WPP widget on your site. You can see this ID string by inspecting the HTML code on your site or you could just add var_dump( $instance['widget_id'] ); at the beginning of the function to see it on your site.
    5. Tweak the code further according to your needs.
    Thread Starter defyogo

    (@defyogo)

    Thanks for the reply. The workaround works fine for me. I’ll mark as resolved

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get different source of thumbnail on wpp’ is closed to new replies.