• Resolved Krzysztof

    (@autori76)


    Hi
    Thank you for the plugin. It works great. Is it possible to make the option that the statistics will be displayed under each article. For example, (views in general: 1000, views today: 10). Your plugin and so it counts to display all articles, so this should not be a problem. I do not know just like with display generally, because I have, set, your plugin to clean the data after 30 days.

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

    (@hcabrera)

    Hi @autori76,

    Add this to your theme’s functions.php file (or via the Code Snippets plugin):

    /**
     * Displays views data summary at the end of the content.
     *
     * @param   string  $content
     * @return  string  $content
     */
    function wpp_display_views_summary( $content ) {
        // Check if we're inside the main loop in a single Post / Page
        if (
            function_exists('wpp_get_views')
            && is_singular(['post', 'page'])
            && in_the_loop()
            && is_main_query()
        ) {
            $post_ID = get_the_ID();
            $total_views = wpp_get_views($post_ID, 'all');
            $todays_views = wpp_get_views($post_ID, 'last24hours');
    
            $views_text = sprintf(
                __('Views in general: %s, Views today: %s'),
                $total_views,
                $todays_views
            );
    
            return $content . '<div class="wpp-views-summary">' . $views_text . '</div>';
        }
    
        return $content;
    }
    add_filter( 'the_content', 'wpp_display_views_summary' );
    Thread Starter Krzysztof

    (@autori76)

    It works. Thank you ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Displaying statistics, under articles – Proposition of options’ is closed to new replies.