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

    (@hcabrera)

    Hi Ben,

    You have these alternatives:

    • WPP filters to customize the HTML output and have that text string removed. This is the recommended way to do it.
    • Modify WPP’s directly, and remove that string from the code (not recommended, since changes will be lost after next update). Open wordpress-popular-posts.php using a text editor, find:
      $stats[] = '<span class="wpp-date">' . sprintf(__('posted on %s', $this->plugin_slug), $date) . '</span>';
      … and replace it with:
      $stats[] = '<span class="wpp-date">' . $date . '</span>';
    Thread Starter Benmjt

    (@benmjt)

    That’s great, thanks Hector.

    Hi Héctor,

    I would like to remove “Posted on” with your first option (WPP filters). But I can’t figure out where to add the filters themselves.

    Thank you in advance.

    wordsinthebucket.com

    Plugin Author Hector Cabrera

    (@hcabrera)

    Hey @wordsinthebucket,

    Ah, you’re right. The wiki doesn’t mention this. You need to put them in your theme’s functions.php.

    Thank you Héctor.

    DoubleDs

    (@doubleds)

    HI.Sorry to revive such an old post. I would like to remove the “posted on” using the WPP Filters method, but unfortunately I do not know much HTML/CSS/Filters and although I tried I can’t figure out how to successfully edit the example I found on the GitHub page from Hector’s link. Do you think you could provide me with a complete example?

    Thank you very much!

    Plugin Author Hector Cabrera

    (@hcabrera)

    Don’t worry. Try this:

    /*
     * Builds custom HTML
     *
     * With this function, I can alter WPP's HTML output from my theme's functions.php.
     * This way, the modification is permanent even if the plugin gets updated.
     *
     * @param   array   $mostpopular
     * @param   array   $instance
     * @return  string
     */
    function my_custom_popular_posts_html_list( $mostpopular, $instance ){
        $output = '<ul class="wpp-list">';
    
        // loop the array of popular posts objects
        foreach( $mostpopular as $popular ) {
    
            $stats = array(); // placeholder for the stats tag
    
            // Comment count option active, display comments
            if ( $instance['stats_tag']['comment_count'] ) {
                // display text in singular or plural, according to comments count
                $stats[] = '<span class="wpp-comments">' . sprintf(
                    _n('1 comment', '%s comments', $popular->comment_count, 'wordpress-popular-posts'),
                    number_format_i18n($popular->comment_count)
                ) . '</span>';
            }
    
            // Pageviews option checked, display views
            if ( $instance['stats_tag']['views'] ) {
    
                // If sorting posts by average views
                if ($instance['order_by'] == 'avg') {
                    // display text in singular or plural, according to views count
                    $stats[] = '<span class="wpp-views">' . sprintf(
                        _n('1 view per day', '%s views per day', intval($popular->pageviews), 'wordpress-popular-posts'),
                        number_format_i18n($popular->pageviews, 2)
                    ) . '</span>';
                } else { // Sorting posts by views
                    // display text in singular or plural, according to views count
                    $stats[] = '<span class="wpp-views">' . sprintf(
                        _n('1 view', '%s views', intval($popular->pageviews), 'wordpress-popular-posts'),
                        number_format_i18n($popular->pageviews)
                    ) . '</span>';
                }
            }
    
            // Author option checked
            if ($instance['stats_tag']['author']) {
                $author = get_the_author_meta('display_name', $popular->uid);
                $display_name = '<a href="' . get_author_posts_url($popular->uid) . '">' . $author . '</a>';
                $stats[] = '<span class="wpp-author">' . sprintf(__('by %s', 'wordpress-popular-posts'), $display_name). '</span>';
            }
    
            // Date option checked
            if ($instance['stats_tag']['date']['active']) {
                $date = date_i18n($instance['stats_tag']['date']['format'], strtotime($popular->date));
                $stats[] = '<span class="wpp-date">' . $date . '</span>';
            }
    
            // Category option checked
            if ($instance['stats_tag']['category']) {
                $post_cat = get_the_category($popular->id);
                $post_cat = (isset($post_cat[0]))
                  ? '<a href="' . get_category_link($post_cat[0]->term_id) . '">' . $post_cat[0]->cat_name . '</a>'
                  : '';
    
                if ($post_cat != '') {
                    $stats[] = '<span class="wpp-category">' . sprintf(__('under %s', 'wordpress-popular-posts'), $post_cat) . '</span>';
                }
            }
    
            // Build stats tag
            if ( !empty($stats) ) {
                $stats = '<div class="wpp-stats">' . join( ' | ', $stats ) . '</div>';
            }
    
            $output .= "<li>";
            $output .= "<a class=\"wpp-post-title\" href=\"" . get_the_permalink( $popular->id ) . "\" title=\"" . esc_attr( $popular->title ) . "\">" . $popular->title . "</a>";
            $output .= $stats;
            $output .= "</li>" . "\n";
    
        }
    
        $output .= '</ul>';
    
        return $output;
    }
    
    add_filter( 'wpp_custom_html', 'my_custom_popular_posts_html_list', 10, 2 );
Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘How to remove 'Posted on…'’ is closed to new replies.