admin管理员组文章数量:1430651
I'm using Jetpack to retrieve the number of views for each blog post. Is there a way to use this to generate a call to the most viewed posts and list them?
I've been wanting to do that for a long time now and I've looked into various plugins, but I'd prefer to hardcode this. Is there a way to write a code so that I could utilize the view count provided by Jetpack?
I looked at similar questions here, but none of them has been answered. A few commenters suggested plugins, but those have been abandoned by now. I couldn't find any up-to-date information.
Right now I'm only calling the "view count" within my single.php like that:
<?php print_page_views(get_the_ID('')); ?>
For that I'm using a plugin called "Post 'n Page Views" that requires Jetpack. I tried looking for the plugin in the Wordpress Dabatase, but it doesn't seem to exist anymore.
I really would appreciate any kind of advice or updated information on this. Thank you so much!
I'm using Jetpack to retrieve the number of views for each blog post. Is there a way to use this to generate a call to the most viewed posts and list them?
I've been wanting to do that for a long time now and I've looked into various plugins, but I'd prefer to hardcode this. Is there a way to write a code so that I could utilize the view count provided by Jetpack?
I looked at similar questions here, but none of them has been answered. A few commenters suggested plugins, but those have been abandoned by now. I couldn't find any up-to-date information.
Right now I'm only calling the "view count" within my single.php like that:
<?php print_page_views(get_the_ID('')); ?>
For that I'm using a plugin called "Post 'n Page Views" that requires Jetpack. I tried looking for the plugin in the Wordpress Dabatase, but it doesn't seem to exist anymore.
I really would appreciate any kind of advice or updated information on this. Thank you so much!
Share Improve this question asked Apr 15, 2013 at 3:30 japanwormjapanworm 5873 gold badges19 silver badges40 bronze badges1 Answer
Reset to default 10There is a Jetpack widget called Top Posts and Pages (Jetpack)
If you check out the [source code][2] for this widget, you can see that it's using the function stats_get_csv()
to retrieve the stats:
$post_view_posts = stats_get_csv( 'postviews', array( 'days' => 2, 'limit' => 10 ) );
If you want to generate your custom most popular list, you can use for example:
if(function_exists('stats_get_csv')){
$popular = stats_get_csv( 'postviews', array( 'days' => 2, 'limit' => 10 ) );
echo '<ol>';
foreach ( $popular as $p ) {
printf('<li><a href="%s">%s</a>(%d)</li>', $p['post_permalink'], $p['post_title'], $p['views'] );
}
echo '</ol>';
}
The function stats_get_csv( $table, $args = null )
is defined in:
http://plugins.trac.wordpress/browser/jetpack/tags/2.2.6/modules/stats.php
where the data is fetched from
http://stats.wordpress/csv.php
Note that stats_get_csv
is caching the data for 5 minutes.
For an example of the what the stats_get_csv
outputs and the API description, please check out this great answer.
本文标签: Popular posts by view with Jetpack
版权声明:本文标题:Popular posts by view with Jetpack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745539354a2662420.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论