exclude posts and home page from stats_get_csv
-
Quick intro: I am a new WordPress user (2 months) and spent quite a bit of time looking for a way to show “most viewed/popular posts” in my archive section. After quite a bit of searching I stumbled upon a function included in Jetpack called stats_get_csv which helped me with this. The problem is that it showed both posts, PAGES AND HOME PAGE.
I’m posting this to see if anyone has suggestions on alternatives or if anyone else can find this helpful in their own project. This particular code gets all your posts since inception and limits it to show the 2 most popular, excluding pages and the home page:
<h4 class="top">Most Popular</h4> <?php $postcount = 0; ?> <?php if ( function_exists('stats_get_csv') && $top_posts = stats_get_csv('postviews', 'days=-1&limit=-1') ) : ?> <?php foreach ( $top_posts as $p ) : ?> <?php $id = $p['post_id']; ?> <?php $posttype = get_post_type($id); ?> <?php if ( $posttype == "post" && $id !== "0") { ?> <?php $postcount++; ?> <!-- How you display your posts here --> <?php } else if ($postcount == 3) { ?> <?php break; ?> <?php }; ?> <?php endforeach; ?> <?php endif; ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘exclude posts and home page from stats_get_csv’ is closed to new replies.