WP-PostViews - Version 1.00beta

Version Description

Download this release

Release Info

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

Version 1.00beta

Files changed (3) hide show
  1. postviews.php +81 -0
  2. readme-install.txt +51 -0
  3. readme.txt +14 -0
postviews.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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(get_post_meta($id, 'views', true));
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
+ global $id;
50
+ $post_views = intval(get_post_meta($id, 'views', true));
51
+ if($display) {
52
+ echo $post_views.' '.$text_views;
53
+ } else {
54
+ return $post_views;
55
+ }
56
+ }
57
+
58
+
59
+ ### Function: Display Most Viewed Page/Post
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
+ echo "- <a href=\"".get_permalink()."\">$post_title</a> ($post_views ".__('Views').")<br />";
76
+ }
77
+ } else {
78
+ _e('N/A');
79
+ }
80
+ }
81
+ ?>
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 the 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