• Resolved laozor

    (@laozor)


    Hello,

    I’ll try to be the more precise I can be, as English is not my native language, so please be understanding ! 🙂 (but don’t hesitate to underline my mistakes)

    (I try to use both “WordPress Popular Posts” AND “Post Thumbnail Editor” plugins)

    Anyway. In fact I may have to distinct questions :

    1- Actualy, in the settings, I’ve selected the thumbnail to be the “featured image”. I’ve used PTE to be sure that my thumbnail will look like what I want it to look like while (175*175) have a “large size” (700*300) for my single.php. But WPP doesn’t use the thumbnail I’ve pre-retailed, but create another one from the large size used in single.php and, obviously, it’s not what I want.
    At this point of my post, I’m not sure of beeing realy understandable, so I’m going to use an example :
    Imagine I’ve got a realy nice pic of me at my previous holidays at the beach. As this pic is realy big, I’ve used PTE to set the thumbnail (175*175) to be only my face (yeah, quite egocentric isn’t it ?) and the large size (700*300) to be a smaller version of the entire pic. Yet, WPP doesn’t use the thumbnail size, but create another one from the large size..
    So my question is : what did I missed ?

    2- I’ve created a specific thumbnail size in my functions.php files simply called “wpp_thumb” and have retailed as I did previously a part of my big pic to be the thumbnail for WPP. I’ve read in another post that the plugin, not used as a widget but with wpp_get_most_popular() cannot use a specific predefined thumbnail size and we have to use the wpp_custom_html filter with the get_the_post_thumbnail() function. However, I’m not comfortable with this and I realy don’t know, even after having read this page what I’ve to do… Can somebody help me ? And if I use this filter for my thumbnail, will my other parameters work as if there weren’t any filter ?
    This is what I’m currently using :

    $args = array('header' => 'Articles Populaires',
    'header_start' => '<h3 class="content-title">',
    'header_end' => '</h3>',
    'post_type' => 'post',
    'limit' => 5,
    'thumbnail_width' => 175,
    'thumbnail_height' => 175,
    'stats_category' => 1,
    'title_length' => 25,
    'stats_date' => 1,
    'stats_date_format' => 'd M Y',
    'post_html' => '<li class="popular-postid">{thumb}<br /><span class="pp-cat">{category}</span><br />{title}<br /><span class="pp-date">{date}</span></li>');					wpp_get_mostpopular( $args );

    You can see it right here : http://ouexperience.esy.es/ (not realy finished, many things to do ! But I’ve hosted it to show you, I usualy run it in local)

    Thank you very much for helping me !

    Laozor

    https://ww.wp.xz.cn/plugins/wordpress-popular-posts/

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

    (@hcabrera)

    Hi Laozor!

    The filters allow you to use your own markup, so parameters like stats_date_format that are specific to certain functionalities (in this case, the {date} Content Tag) are not used at all.

    Here’s your custom HTML markup using the wpp_post filter hook:

    function my_custom_single_popular_post( $post_html, $p, $instance ){
    
        $output = '<li class="popular-postid">' . get_the_post_thumbnail( $p->id, 'wpp_thumb' ) . '<br /><span class="pp-cat">' . get_the_category( $p->id ) . '</span><br />' . $p->title . '<br /><span class="pp-date">' . date( 'd M Y', strtotime( $p->date ) ) . '</span></li>';
    
        return $output;
    
    }
    add_filter( 'wpp_post', 'my_custom_single_popular_post', 10, 3 );
    Thread Starter laozor

    (@laozor)

    Hello Hector Cabrera !

    Thank you very much for your help ! I had to make some few changes to the code you gave me, so I post my final code here.
    In particular, I had to add a ‘foreach’ concerning the categories, as the code was only returning the word “Array”.. And I added a substr() for my title length 🙂

    function my_custom_single_popular_post( $post_html, $p, $instance ){
        $pp_categories = get_the_category($p->id);
        if($pp_categories){
            foreach ($pp_categories as $pp_category){
                $pp_categoryout = '<a href="'.get_category_link( $pp_category->term_id ).'" class="cat-id-' . $pp_category->term_id . '" title="' . esc_attr( sprintf( __( "Voir tous les articles dans %s" ), $pp_category->name ) ) . '">'.$pp_category->cat_name.'</a>';
            }
        }
        $output = '
            <li class="popular-postid">'
                . get_the_post_thumbnail( $p->id, 'wpp_thumb' ) . '<br />
                <span class="pp-cat">' . trim($pp_categoryout) .'</span><br />
                <a href="'.get_permalink($p->id).'" title="'. esc_attr($p->title) .'" class="wpp-post-title" >'. substr($p->title, 0, 25).' (...)</a><br />
                <span class="pp-date">' . date( 'd M Y', strtotime( $p->date ) ) . '</span>
            </li>';
    
        return $output;
    }
    
    add_filter( 'wpp_post', 'my_custom_single_popular_post', 10, 3 );

    It’s all good now ! Again, thank you very much ! 🙂

    Plugin Author Hector Cabrera

    (@hcabrera)

    Ah, I forgot about that. Good catch!

    Enjoy the plugin! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Using a specific thumbnail size’ is closed to new replies.