WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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, gmazzap Nov 27 '14 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.

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.