Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i'am currently using latest version of jetpack. So the stats plugin is also included in this plugin. But now i want to display the number of views the single post get on the single.php file using the data from Stats plugin included in jetpack. So how can i do this?

share|improve this question

closed as off-topic by Pieter Goosen, cybmeta, birgire, Mark Kaplun, G. M. Nov 27 at 14:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

Put this into your functions.php file:

function userfunc_get_post_views($postID) {
        global $post_stats;
        foreach ( $post_stats as $p ) {
            if ( $p['post_id'] == $postID ) { ?>
                <span class='stats-post-views'>
                    <?php echo number_format_i18n( $p['views']) . ' views'; ?>
                </span>
        <?php }
    }
}

and then into your single.php file where you want the views to be displayed:

<?php userfunc_get_post_views(get_the_ID()); ?>

This will wrap it in a div with the class of stats-post-views so you can style it.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.