WP-PostViews - Version 1.00

Version Description

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-PostViews
Version 1.00
Comparing to
See all releases

Version 1.00

Files changed (3) hide show
  1. postviews.php +112 -0
  2. readme-install.txt +51 -0
  3. readme.txt +14 -0
postviews.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-PostViews
4
+ Plugin URI: http://www.lesterchan.net/portfolio/programming.php
5
+ Description: Enables You To Display How Many Time A Post Had Been Viewed.
6
+ Version: 1.00
7
+ Author: GaMerZ
8
+ Author URI: http://www.lesterchan.net
9
+ */
10
+
11
+
12
+ /* Copyright 2005 Lester Chan (email : gamerz84@hotmail.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ */
28
+
29
+
30
+ ### Function: Calculate Post Views
31
+ add_action('loop_start', 'process_postviews');
32
+ function process_postviews() {
33
+ global $id;
34
+ $post_views = intval(post_custom('views'));
35
+ if(empty($_COOKIE[USER_COOKIE])) {
36
+ if(is_single() || is_page()) {
37
+ if($post_views > 0) {
38
+ update_post_meta($id, 'views', ($post_views+1));
39
+ } else {
40
+ add_post_meta($id, 'views', 1);
41
+ }
42
+ }
43
+ }
44
+ }
45
+
46
+
47
+ ### Function: Display The Post Views
48
+ function the_views($text_views = 'Views', $display = true) {
49
+ $post_views = intval(post_custom('views'));
50
+ if($display) {
51
+ echo number_format($post_views).' '.$text_views;
52
+ } else {
53
+ return $post_views;
54
+ }
55
+ }
56
+
57
+
58
+ ### Function: Display Most Viewed Page/Post
59
+ if(!function_exists('get_most_viewed')) {
60
+ function get_most_viewed($mode = '', $limit = 10) {
61
+ global $wpdb, $post;
62
+ $where = '';
63
+ if($mode == 'post') {
64
+ $where = 'post_status = \'publish\'';
65
+ } elseif($mode == 'page') {
66
+ $where = 'post_status = \'static\'';
67
+ } else {
68
+ $where = '(post_status = \'publish\' OR post_status = \'static\')';
69
+ }
70
+ $most_viewed = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, CAST(meta_value AS UNSIGNED) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");
71
+ if($most_viewed) {
72
+ foreach ($most_viewed as $post) {
73
+ $post_title = htmlspecialchars(stripslashes($post->post_title));
74
+ $post_views = intval($post->views);
75
+ $post_views = number_format($post_views);
76
+ echo "<li><a href=\"".get_permalink()."\">$post_title</a> ($post_views ".__('Views').")</li>";
77
+ }
78
+ } else {
79
+ echo '<li>'.__('N/A').'</li>';
80
+ }
81
+ }
82
+ }
83
+
84
+
85
+ ### Added by Paolo Tagliaferri (http://www.vortexmind.net - webmaster@vortexmind.net)
86
+ function get_timespan_most_viewed($mode = '', $limit = 10,$days = 7) {
87
+ global $wpdb, $post;
88
+ $limit_date = current_time('timestamp') - ($days*86400);
89
+ $limit_date = date("Y-m-d H:i:s",$limit_date);
90
+ $where = '';
91
+ if($mode == 'post') {
92
+ $where = 'post_status = \'publish\'';
93
+ } elseif($mode == 'page') {
94
+ $where = 'post_status = \'static\'';
95
+ } else {
96
+ $where = '(post_status = \'publish\' OR post_status = \'static\')';
97
+ }
98
+ $most_viewed = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, CAST(meta_value AS UNSIGNED) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND post_date > '".$limit_date."' AND $where AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");
99
+ if($most_viewed) {
100
+ echo "<ul>";
101
+ foreach ($most_viewed as $post) {
102
+ $post_title = htmlspecialchars(stripslashes($post->post_title));
103
+ $post_views = intval($post->views);
104
+ $post_views = number_format($post_views);
105
+ echo "<li><a href=\"".get_permalink()."\">$post_title</a> ($post_views ".__('Views').")</li>";
106
+ }
107
+ echo "</ul>";
108
+ } else {
109
+ _e('N/A');
110
+ }
111
+ }
112
+ ?>
readme-install.txt ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Installation Instructions
2
+ --------------------------------------------------
3
+ // Open wp-content/plugins folder
4
+
5
+ Put:
6
+ ------------------------------------------------------------------
7
+ postviews.php
8
+ ------------------------------------------------------------------
9
+
10
+
11
+ // Activate WP-PostViews plugin
12
+
13
+
14
+
15
+
16
+
17
+ -> Usage Instructions
18
+ --------------------------------------------------
19
+ // Open wp-content/themes/<YOUR THEME NAME>/index.php OR single.php OR page.php
20
+
21
+ Find:
22
+ ------------------------------------------------------------------
23
+ <?php while (have_posts()) : the_post(); ?>
24
+ ------------------------------------------------------------------
25
+ Add Anywhere Below It:
26
+ ------------------------------------------------------------------
27
+ <?php if(function_exists('the_views')) { the_views(); } ?>
28
+ ------------------------------------------------------------------
29
+ Note:
30
+ ------------------------------------------------------------------
31
+ The first value you pass in is the text for views.
32
+ Default: the_views('Views');
33
+ ------------------------------------------------------------------
34
+
35
+
36
+ // Post Views Stats (You can place it anywhere outside the WP Loop)
37
+
38
+ // To Get Most Viewed Post
39
+
40
+ Use:
41
+ ------------------------------------------------------------------
42
+ <?php if (function_exists('get_most_viewed')): ?>
43
+ <?php get_most_viewed(); ?>
44
+ <?php endif; ?>
45
+ ------------------------------------------------------------------
46
+ Note:
47
+ ------------------------------------------------------------------
48
+ The first value you pass in is what you want to get, 'post', 'page' or 'both'.
49
+ The second value you pass in is the number of post you want to get.
50
+ Default: get_most_viewed('both', 10);
51
+ ------------------------------------------------------------------
readme.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Post Views Plugin For WordPress 2.0
2
+ --------------------------------------------------
3
+ Author -> Lester 'GaMerZ' Chan
4
+ Email -> gamerz84@hotmail.com
5
+ Website -> http://www.lesterchan.net/
6
+ Demo -> http://www.lesterchan.net/wordpress/
7
+ Documentation -> http://dev.wp-plugins.org/wiki/wp-postviews
8
+ Development -> http://dev.wp-plugins.org/browser/wp-postviews/
9
+ Updated -> 1st March 2006
10
+ --------------------------------------------------
11
+
12
+
13
+ // Version 1.00 (01-03-2006)
14
+ - NEW: Initial Release