Version Description
Download this release
Release Info
Developer | Ajay |
Plugin | Top 10 – Popular posts plugin for WordPress |
Version | 1.3 |
Comparing to | |
See all releases |
Code changes from version 1.2 to 1.3
- admin.inc.php +170 -34
- readme.txt +10 -0
- top-10-addcount.js.php +8 -6
- top-10-counter.js.php +5 -3
- top-10-daily.js.php +52 -0
- top-10.php +85 -61
admin.inc.php
CHANGED
@@ -12,12 +12,15 @@ function tptn_options() {
|
|
12 |
if($_POST['tptn_save']){
|
13 |
$tptn_settings[title] = ($_POST['title']);
|
14 |
$tptn_settings[title_daily] = ($_POST['title_daily']);
|
|
|
15 |
$tptn_settings[limit] = ($_POST['limit']);
|
16 |
$tptn_settings[count_disp_form] = ($_POST['count_disp_form']);
|
17 |
$tptn_settings[add_to_content] = (($_POST['add_to_content']) ? true : false);
|
18 |
$tptn_settings[exclude_pages] = (($_POST['exclude_pages']) ? true : false);
|
19 |
$tptn_settings[track_authors] = (($_POST['track_authors']) ? true : false);
|
20 |
$tptn_settings[pv_in_admin] = (($_POST['pv_in_admin']) ? true : false);
|
|
|
|
|
21 |
$tptn_settings[show_credit] = (($_POST['show_credit']) ? true : false);
|
22 |
|
23 |
update_option('ald_tptn_settings', $tptn_settings);
|
@@ -85,6 +88,12 @@ function tptn_options() {
|
|
85 |
<input type="textbox" name="title_daily" id="title_daily" value="<?php echo stripslashes($tptn_settings[title_daily]); ?>">
|
86 |
</label>
|
87 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
<p>
|
89 |
<label>
|
90 |
<input type="checkbox" name="exclude_pages" id="exclude_pages" <?php if ($tptn_settings[exclude_pages]) echo 'checked="checked"' ?> />
|
@@ -97,6 +106,18 @@ function tptn_options() {
|
|
97 |
<?php _e('Track visits of authors on their own posts?','ald_tptn_plugin'); ?>
|
98 |
</label>
|
99 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
<p>
|
101 |
<label>
|
102 |
<input type="checkbox" name="pv_in_admin" id="pv_in_admin" <?php if ($tptn_settings[pv_in_admin]) echo 'checked="checked"' ?> />
|
@@ -117,7 +138,7 @@ function tptn_options() {
|
|
117 |
</p>
|
118 |
<p>
|
119 |
<input type="submit" name="tptn_save" id="tptn_save" value="Save Options" style="border:#00CC00 1px solid" />
|
120 |
-
<input name="tptn_default" type="submit" id="tptn_default" value="Default Options" style="border:#FF0000 1px solid" onclick="if (!confirm('<?php _e('Do you want to set options to Default?
|
121 |
</p>
|
122 |
</fieldset>
|
123 |
</form>
|
@@ -126,6 +147,20 @@ function tptn_options() {
|
|
126 |
|
127 |
}
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
/* Add menu item in WP-Admin */
|
130 |
function tptn_adminmenu() {
|
131 |
if (function_exists('current_user_can')) {
|
@@ -143,62 +178,158 @@ function tptn_adminmenu() {
|
|
143 |
|
144 |
if ((function_exists('add_options_page'))&&($tptn_is_admin)) {
|
145 |
add_options_page(__("Top 10", 'myald_tptn_plugin'), __("Top 10", 'myald_tptn_plugin'), 9, 'tptn_options', 'tptn_options');
|
146 |
-
|
|
|
147 |
}
|
148 |
add_action('admin_menu', 'tptn_adminmenu');
|
149 |
|
150 |
|
151 |
/* Create a Dashboard Widget */
|
152 |
-
|
153 |
-
function tptn_pop_dashboard() {
|
154 |
global $wpdb, $siteurl, $tableposts, $id;
|
155 |
|
156 |
$table_name = $wpdb->prefix . "top_ten";
|
|
|
|
|
157 |
$tptn_settings = tptn_read_options();
|
158 |
-
$limit = $tptn_settings['limit'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
|
|
165 |
|
166 |
$results = $wpdb->get_results($sql);
|
167 |
-
|
168 |
-
echo '<ul>';
|
169 |
if ($results) {
|
170 |
foreach ($results as $result) {
|
171 |
-
|
172 |
}
|
173 |
}
|
174 |
-
|
175 |
-
|
176 |
-
}
|
177 |
-
|
178 |
-
// Dashboard for Daily Popular Posts
|
179 |
-
function tptn_pop_daily_dashboard() {
|
180 |
-
global $wpdb, $siteurl, $tableposts, $id;
|
181 |
|
182 |
-
$
|
183 |
-
|
184 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
$results = $wpdb->get_results($sql);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
|
194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
if ($results) {
|
196 |
foreach ($results as $result) {
|
197 |
-
|
|
|
|
|
198 |
}
|
199 |
}
|
200 |
-
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
}
|
203 |
|
204 |
function tptn_pop_dashboard_setup() {
|
@@ -209,6 +340,7 @@ function tptn_pop_dashboard_setup() {
|
|
209 |
}
|
210 |
add_action('wp_dashboard_setup', 'tptn_pop_dashboard_setup');
|
211 |
|
|
|
212 |
/* Display page views on the Edit Posts / Pages screen */
|
213 |
// Add an extra column
|
214 |
function tptn_column($cols) {
|
@@ -231,10 +363,14 @@ function tptn_value($column_name, $id) {
|
|
231 |
|
232 |
$cntaccess .= ' / ';
|
233 |
|
|
|
234 |
$table_name = $wpdb->prefix . "top_ten_daily";
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
-
$resultscount = $wpdb->get_row("select postnumber, cntaccess from $table_name WHERE postnumber = $id");
|
237 |
-
$cntaccess .= number_format((($resultscount) ? $resultscount->cntaccess : 0));
|
238 |
echo $cntaccess;
|
239 |
}
|
240 |
}
|
12 |
if($_POST['tptn_save']){
|
13 |
$tptn_settings[title] = ($_POST['title']);
|
14 |
$tptn_settings[title_daily] = ($_POST['title_daily']);
|
15 |
+
$tptn_settings[daily_range] = ($_POST['daily_range']);
|
16 |
$tptn_settings[limit] = ($_POST['limit']);
|
17 |
$tptn_settings[count_disp_form] = ($_POST['count_disp_form']);
|
18 |
$tptn_settings[add_to_content] = (($_POST['add_to_content']) ? true : false);
|
19 |
$tptn_settings[exclude_pages] = (($_POST['exclude_pages']) ? true : false);
|
20 |
$tptn_settings[track_authors] = (($_POST['track_authors']) ? true : false);
|
21 |
$tptn_settings[pv_in_admin] = (($_POST['pv_in_admin']) ? true : false);
|
22 |
+
$tptn_settings[disp_list_count] = (($_POST['disp_list_count']) ? true : false);
|
23 |
+
$tptn_settings[d_use_js] = (($_POST['d_use_js']) ? true : false);
|
24 |
$tptn_settings[show_credit] = (($_POST['show_credit']) ? true : false);
|
25 |
|
26 |
update_option('ald_tptn_settings', $tptn_settings);
|
88 |
<input type="textbox" name="title_daily" id="title_daily" value="<?php echo stripslashes($tptn_settings[title_daily]); ?>">
|
89 |
</label>
|
90 |
</p>
|
91 |
+
<p>
|
92 |
+
<label>
|
93 |
+
<?php _e('Daily Popular should contain views of how many days? ','ald_tptn_plugin'); ?>
|
94 |
+
<input type="textbox" name="daily_range" id="daily_range" size="3" value="<?php echo stripslashes($tptn_settings[daily_range]); ?>">
|
95 |
+
</label>
|
96 |
+
</p>
|
97 |
<p>
|
98 |
<label>
|
99 |
<input type="checkbox" name="exclude_pages" id="exclude_pages" <?php if ($tptn_settings[exclude_pages]) echo 'checked="checked"' ?> />
|
106 |
<?php _e('Track visits of authors on their own posts?','ald_tptn_plugin'); ?>
|
107 |
</label>
|
108 |
</p>
|
109 |
+
<p>
|
110 |
+
<label>
|
111 |
+
<input type="checkbox" name="disp_list_count" id="disp_list_count" <?php if ($tptn_settings[disp_list_count]) echo 'checked="checked"' ?> />
|
112 |
+
<?php _e('Display number of page views in popular lists?','ald_tptn_plugin'); ?>
|
113 |
+
</label>
|
114 |
+
</p>
|
115 |
+
<p>
|
116 |
+
<label>
|
117 |
+
<input type="checkbox" name="d_use_js" id="d_use_js" <?php if ($tptn_settings[d_use_js]) echo 'checked="checked"' ?> />
|
118 |
+
<?php _e('Force daily posts\' list to be dynamic? This options uses JavaScript to load the post and can increase your page load time','ald_tptn_plugin'); ?>
|
119 |
+
</label>
|
120 |
+
</p>
|
121 |
<p>
|
122 |
<label>
|
123 |
<input type="checkbox" name="pv_in_admin" id="pv_in_admin" <?php if ($tptn_settings[pv_in_admin]) echo 'checked="checked"' ?> />
|
138 |
</p>
|
139 |
<p>
|
140 |
<input type="submit" name="tptn_save" id="tptn_save" value="Save Options" style="border:#00CC00 1px solid" />
|
141 |
+
<input name="tptn_default" type="submit" id="tptn_default" value="Default Options" style="border:#FF0000 1px solid" onclick="if (!confirm('<?php _e('Do you want to set options to Default?','ald_tptn_plugin'); ?>')) return false;" />
|
142 |
</p>
|
143 |
</fieldset>
|
144 |
</form>
|
147 |
|
148 |
}
|
149 |
|
150 |
+
function tptn_manage() {
|
151 |
+
$paged = intval($_GET['paged']);
|
152 |
+
$limit = intval($_GET['limit']);
|
153 |
+
$daily = $_GET['daily'];
|
154 |
+
|
155 |
+
echo '<div class="wrap">';
|
156 |
+
echo '<h2>';
|
157 |
+
if (!$daily) echo 'Popular Posts'; else echo 'Daily Popular Posts';
|
158 |
+
echo '</h2>';
|
159 |
+
echo '<div style="border: #ccc 1px solid; padding: 10px">';
|
160 |
+
echo tptn_pop_display($daily,$paged,$limit);
|
161 |
+
echo '</div></div>';
|
162 |
+
}
|
163 |
+
|
164 |
/* Add menu item in WP-Admin */
|
165 |
function tptn_adminmenu() {
|
166 |
if (function_exists('current_user_can')) {
|
178 |
|
179 |
if ((function_exists('add_options_page'))&&($tptn_is_admin)) {
|
180 |
add_options_page(__("Top 10", 'myald_tptn_plugin'), __("Top 10", 'myald_tptn_plugin'), 9, 'tptn_options', 'tptn_options');
|
181 |
+
add_posts_page(__("Popular Posts", 'myald_tptn_plugin'), __("Top 10", 'myald_tptn_plugin'), 9, 'tptn_manage', 'tptn_manage');
|
182 |
+
}
|
183 |
}
|
184 |
add_action('admin_menu', 'tptn_adminmenu');
|
185 |
|
186 |
|
187 |
/* Create a Dashboard Widget */
|
188 |
+
function tptn_pop_display($daily = false, $page = 0, $limit = 10) {
|
|
|
189 |
global $wpdb, $siteurl, $tableposts, $id;
|
190 |
|
191 |
$table_name = $wpdb->prefix . "top_ten";
|
192 |
+
if ($daily) $table_name .= "_daily"; // If we're viewing daily posts, set this to true
|
193 |
+
|
194 |
$tptn_settings = tptn_read_options();
|
195 |
+
if (!($limit)) $limit = $tptn_settings['limit'];
|
196 |
+
if (!($page)) $page = 0; // Default page value.
|
197 |
+
|
198 |
+
if(!$daily) {
|
199 |
+
$sql = "SELECT postnumber, cntaccess , ID, post_type ";
|
200 |
+
$sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
201 |
+
if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
|
202 |
+
$sql .= "AND post_status = 'publish' ";
|
203 |
+
$sql .= "ORDER BY cntaccess DESC";
|
204 |
+
} else {
|
205 |
+
$daily_range = $tptn_settings[daily_range]. ' DAY';
|
206 |
+
$current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $daily_range), INTERVAL 1 DAY) ");
|
207 |
|
208 |
+
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
|
209 |
+
$sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
210 |
+
if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
|
211 |
+
$sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' ";
|
212 |
+
$sql .= "GROUP BY postnumber ";
|
213 |
+
$sql .= "ORDER BY sumCount DESC";
|
214 |
+
}
|
215 |
|
216 |
$results = $wpdb->get_results($sql);
|
217 |
+
$numrows = 0;
|
|
|
218 |
if ($results) {
|
219 |
foreach ($results as $result) {
|
220 |
+
$numrows++;
|
221 |
}
|
222 |
}
|
223 |
+
|
224 |
+
$pages = intval($numrows/$limit); // Number of results pages.
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
+
// $pages now contains int of pages, unless there is a remainder from division.
|
227 |
+
|
228 |
+
if ($numrows % $limit) {$pages++;} // has remainder so add one page
|
229 |
+
|
230 |
+
$current = ($page/$limit) + 1; // Current page number.
|
231 |
+
|
232 |
+
if (($pages < 1) || ($pages == 0)) {$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
|
233 |
+
else { $total = $pages;} // Else total pages is $pages value.
|
234 |
+
|
235 |
+
$first = $page + 1; // The first result.
|
236 |
+
|
237 |
+
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
|
238 |
+
else{$last = $numrows;} // If last results page, last result equals total number of results.
|
239 |
|
240 |
+
if(!$daily) {
|
241 |
+
$sql = "SELECT postnumber, cntaccess , ID, post_type ";
|
242 |
+
$sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
243 |
+
if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
|
244 |
+
$sql .= "AND post_status = 'publish' ";
|
245 |
+
$sql .= "ORDER BY cntaccess DESC LIMIT $page, $limit";
|
246 |
+
} else {
|
247 |
+
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
|
248 |
+
$sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
249 |
+
if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
|
250 |
+
$sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' ";
|
251 |
+
$sql .= "GROUP BY postnumber ";
|
252 |
+
$sql .= "ORDER BY sumCount DESC LIMIT $page, $limit";
|
253 |
+
}
|
254 |
|
255 |
$results = $wpdb->get_results($sql);
|
256 |
+
|
257 |
+
$output = '<div id="tptn_popular_posts">';
|
258 |
+
$output .= '<table width="100%" border="0">
|
259 |
+
<tr>
|
260 |
+
<td width="50%" align="left">
|
261 |
+
Results <strong>'.$first.'</strong> - <strong>'.$last.'</strong> of <strong>'.$numrows.'</strong>
|
262 |
+
</td>
|
263 |
+
<td width="50%" align="right">
|
264 |
+
Page <strong>'.$current.'</strong> of <strong>'.$total.'</strong>
|
265 |
+
</td>
|
266 |
+
</tr>
|
267 |
+
<tr>
|
268 |
+
<td colspan="2" align="right"> </td>
|
269 |
+
</tr>
|
270 |
+
<tr>
|
271 |
+
<td align="left">';
|
272 |
|
273 |
+
if(!$daily) {
|
274 |
+
$output .= '<a href="./edit.php?page=tptn_manage&daily=1">View Daily Popular Posts</a></td>';
|
275 |
+
} else {
|
276 |
+
$output .= '<a href="./edit.php?page=tptn_manage&daily=0">View Overall Popular Posts</a></td>';
|
277 |
+
}
|
278 |
+
$output .= '<td align="right">
|
279 |
+
Results per-page: <a href="./edit.php?page=tptn_manage&daily='.$daily.'&limit=10">10</a> | <a href="./edit.php?page=tptn_manage&daily='.$daily.'&limit=20">20</a> | <a href="./edit.php?page=tptn_manage&daily='.$daily.'&limit=50">50</a> | <a href="./edit.php?page=tptn_manage&daily='.$daily.'&limit=100">100</a>
|
280 |
+
</td>
|
281 |
+
</tr>
|
282 |
+
<tr>
|
283 |
+
<td colspan="2" align="right"><hr /></td>
|
284 |
+
</tr>
|
285 |
+
</table>';
|
286 |
+
|
287 |
+
|
288 |
+
$output .= '<ul>';
|
289 |
if ($results) {
|
290 |
foreach ($results as $result) {
|
291 |
+
$output .= '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>';
|
292 |
+
if ($daily) $output .= ' ('.$result->sumCount.')'; else $output .= ' ('.$result->cntaccess.')';
|
293 |
+
$output .= '</li>';
|
294 |
}
|
295 |
}
|
296 |
+
$output .= '</ul>';
|
297 |
+
|
298 |
+
$output .= '<p align="center">';
|
299 |
+
if ($page != 0) { // Don't show back link if current page is first page.
|
300 |
+
$back_page = $page - $limit;
|
301 |
+
$output .= "<a href=\"./edit.php?page=tptn_manage&paged=$back_page&daily=$daily&limit=$limit\">« Previous</a> \n";
|
302 |
+
}
|
303 |
+
|
304 |
+
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
|
305 |
+
{
|
306 |
+
$ppage = $limit*($i - 1);
|
307 |
+
if ($ppage == $page){
|
308 |
+
$output .= ("<b>$i</b>\n");} // If current page don't give link, just text.
|
309 |
+
else{
|
310 |
+
$output .= ("<a href=\"./edit.php?page=tptn_manage&paged=$ppage&daily=$daily&limit=$limit\">$i</a> \n");
|
311 |
+
}
|
312 |
+
}
|
313 |
+
|
314 |
+
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
|
315 |
+
$next_page = $page + $limit;
|
316 |
+
$output .= " <a href=\"./edit.php?page=tptn_manage&paged=$next_page&daily=$daily&limit=$limit\">Next »</a>";
|
317 |
+
}
|
318 |
+
$output .= '</p>';
|
319 |
+
$output .= '<p style="text-align:center;border-top: #000 1px solid">Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></p>';
|
320 |
+
$output .= '</div>';
|
321 |
+
|
322 |
+
return $output;
|
323 |
+
|
324 |
+
}
|
325 |
+
|
326 |
+
// Dashboard for Popular Posts
|
327 |
+
function tptn_pop_dashboard() {
|
328 |
+
echo tptn_pop_display(false,0,10);
|
329 |
+
}
|
330 |
+
// Dashboard for Daily Popular Posts
|
331 |
+
function tptn_pop_daily_dashboard() {
|
332 |
+
echo tptn_pop_display(true,0,10);
|
333 |
}
|
334 |
|
335 |
function tptn_pop_dashboard_setup() {
|
340 |
}
|
341 |
add_action('wp_dashboard_setup', 'tptn_pop_dashboard_setup');
|
342 |
|
343 |
+
|
344 |
/* Display page views on the Edit Posts / Pages screen */
|
345 |
// Add an extra column
|
346 |
function tptn_column($cols) {
|
363 |
|
364 |
$cntaccess .= ' / ';
|
365 |
|
366 |
+
// Now process daily count
|
367 |
$table_name = $wpdb->prefix . "top_ten_daily";
|
368 |
+
|
369 |
+
$daily_range = $tptn_settings[daily_range]. ' DAY';
|
370 |
+
$current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $daily_range), INTERVAL 1 DAY) ");
|
371 |
+
$resultscount = $wpdb->get_row("SELECT postnumber, SUM(cntaccess) as sumCount FROM $table_name WHERE postnumber = $id AND dp_date >= '$current_date' GROUP BY postnumber ");
|
372 |
+
$cntaccess .= number_format((($resultscount) ? $resultscount->sumCount : 0));
|
373 |
|
|
|
|
|
374 |
echo $cntaccess;
|
375 |
}
|
376 |
}
|
readme.txt
CHANGED
@@ -28,6 +28,11 @@ Includes a sidebar widget to display the popular posts. And, all settings can be
|
|
28 |
|
29 |
= Changelog =
|
30 |
|
|
|
|
|
|
|
|
|
|
|
31 |
* 1.2
|
32 |
- Do not display Drafts in Related Posts anymore
|
33 |
- Option to disable tracking author visits on their own posts
|
@@ -52,6 +57,8 @@ Includes a sidebar widget to display the popular posts. And, all settings can be
|
|
52 |
|
53 |
5. Goto Appearance > Widgets to add the Popular Posts sidebar widget to your theme
|
54 |
|
|
|
|
|
55 |
|
56 |
|
57 |
== Frequently Asked Questions ==
|
@@ -60,6 +67,9 @@ Includes a sidebar widget to display the popular posts. And, all settings can be
|
|
60 |
|
61 |
WordPress 2.5 or above
|
62 |
|
|
|
|
|
|
|
63 |
|
64 |
= Can I customize what is displayed? =
|
65 |
|
28 |
|
29 |
= Changelog =
|
30 |
|
31 |
+
* 1.3
|
32 |
+
- "Daily Popular" can now be selected over user selectable number of days.
|
33 |
+
- Option to turn off display of number of pageviews in popular posts list
|
34 |
+
- Option to make "Daily Popular" list compatible with caching plugins
|
35 |
+
- Posts > Top 10 page to view detailed list of popular posts
|
36 |
* 1.2
|
37 |
- Do not display Drafts in Related Posts anymore
|
38 |
- Option to disable tracking author visits on their own posts
|
57 |
|
58 |
5. Goto Appearance > Widgets to add the Popular Posts sidebar widget to your theme
|
59 |
|
60 |
+
6. Goto Posts > Top 10 to view the list of popular posts
|
61 |
+
|
62 |
|
63 |
|
64 |
== Frequently Asked Questions ==
|
67 |
|
68 |
WordPress 2.5 or above
|
69 |
|
70 |
+
= Can this plugin replace Google Analytics? =
|
71 |
+
|
72 |
+
Never. This plugin is designed to only track the number of pageviews on your blog posts and display the same. It cannot replace Google Analytics or any other full fledged statistics application.
|
73 |
|
74 |
= Can I customize what is displayed? =
|
75 |
|
top-10-addcount.js.php
CHANGED
@@ -20,28 +20,30 @@ function tptn_inc_count() {
|
|
20 |
|
21 |
$id = intval($_GET['top_ten_id']);
|
22 |
if($id > 0) {
|
23 |
-
$results = $wpdb->get_results("
|
24 |
$test = 0;
|
25 |
if ($results) {
|
26 |
foreach ($results as $result) {
|
27 |
-
$wpdb->query("
|
28 |
$test = 1;
|
29 |
}
|
30 |
}
|
31 |
if ($test == 0) {
|
32 |
-
$wpdb->query("
|
33 |
}
|
34 |
// Now update daily count
|
35 |
-
$
|
|
|
|
|
36 |
$test = 0;
|
37 |
if ($results) {
|
38 |
foreach ($results as $result) {
|
39 |
-
$wpdb->query("
|
40 |
$test = 1;
|
41 |
}
|
42 |
}
|
43 |
if ($test == 0) {
|
44 |
-
$wpdb->query("
|
45 |
}
|
46 |
}
|
47 |
}
|
20 |
|
21 |
$id = intval($_GET['top_ten_id']);
|
22 |
if($id > 0) {
|
23 |
+
$results = $wpdb->get_results("SELECT postnumber, cntaccess FROM $table_name WHERE postnumber = '$id'");
|
24 |
$test = 0;
|
25 |
if ($results) {
|
26 |
foreach ($results as $result) {
|
27 |
+
$wpdb->query("UPDATE $table_name SET cntaccess = cntaccess + 1 WHERE postnumber = $result->postnumber");
|
28 |
$test = 1;
|
29 |
}
|
30 |
}
|
31 |
if ($test == 0) {
|
32 |
+
$wpdb->query("INSERT INTO $table_name (postnumber, cntaccess) VALUES('$id', '1')");
|
33 |
}
|
34 |
// Now update daily count
|
35 |
+
$current_date = $wpdb->get_var("SELECT CURDATE() ");
|
36 |
+
|
37 |
+
$results = $wpdb->get_results("SELECT postnumber, cntaccess, dp_date FROM $top_ten_daily WHERE postnumber = '$id' AND dp_date = '$current_date' ");
|
38 |
$test = 0;
|
39 |
if ($results) {
|
40 |
foreach ($results as $result) {
|
41 |
+
$wpdb->query("UPDATE $top_ten_daily SET cntaccess = cntaccess + 1 WHERE postnumber = $result->postnumber AND dp_date = '$current_date' ");
|
42 |
$test = 1;
|
43 |
}
|
44 |
}
|
45 |
if ($test == 0) {
|
46 |
+
$wpdb->query("INSERT INTO $top_ten_daily (postnumber, cntaccess, dp_date) VALUES('$id', '1', '$current_date' )");
|
47 |
}
|
48 |
}
|
49 |
}
|
top-10-counter.js.php
CHANGED
@@ -23,13 +23,15 @@ function tptn_disp_count() {
|
|
23 |
$id = intval($_GET['top_ten_id']);
|
24 |
if($id > 0) {
|
25 |
|
26 |
-
$resultscount = $wpdb->get_row("
|
27 |
$cntaccess = number_format((($resultscount) ? $resultscount->cntaccess : 0));
|
28 |
$count_disp_form = str_replace("%totalcount%", $cntaccess, $count_disp_form);
|
29 |
|
30 |
// Now process daily count
|
31 |
-
$
|
32 |
-
$
|
|
|
|
|
33 |
$count_disp_form = str_replace("%dailycount%", $cntaccess, $count_disp_form);
|
34 |
|
35 |
echo 'document.write("'.$count_disp_form.'")';
|
23 |
$id = intval($_GET['top_ten_id']);
|
24 |
if($id > 0) {
|
25 |
|
26 |
+
$resultscount = $wpdb->get_row("SELECT postnumber, cntaccess FROM $table_name WHERE postnumber = $id");
|
27 |
$cntaccess = number_format((($resultscount) ? $resultscount->cntaccess : 0));
|
28 |
$count_disp_form = str_replace("%totalcount%", $cntaccess, $count_disp_form);
|
29 |
|
30 |
// Now process daily count
|
31 |
+
$daily_range = $tptn_settings[daily_range]. ' DAY';
|
32 |
+
$current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $daily_range), INTERVAL 1 DAY) ");
|
33 |
+
$resultscount = $wpdb->get_row("SELECT postnumber, SUM(cntaccess) as sumCount FROM $table_name_daily WHERE postnumber = $id AND dp_date >= '$current_date' GROUP BY postnumber ");
|
34 |
+
$cntaccess = number_format((($resultscount) ? $resultscount->sumCount : 0));
|
35 |
$count_disp_form = str_replace("%dailycount%", $cntaccess, $count_disp_form);
|
36 |
|
37 |
echo 'document.write("'.$count_disp_form.'")';
|
top-10-daily.js.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
//"top-10-daily.js.php" Display Daily Popular Lists.
|
3 |
+
Header("content-type: application/x-javascript");
|
4 |
+
|
5 |
+
if (!function_exists('add_action')) {
|
6 |
+
$wp_root = '../../..';
|
7 |
+
if (file_exists($wp_root.'/wp-load.php')) {
|
8 |
+
require_once($wp_root.'/wp-load.php');
|
9 |
+
} else {
|
10 |
+
require_once($wp_root.'/wp-config.php');
|
11 |
+
}
|
12 |
+
}
|
13 |
+
|
14 |
+
// Display counter using Ajax
|
15 |
+
function tptn_daily_lists() {
|
16 |
+
global $wpdb, $siteurl, $tableposts, $id;
|
17 |
+
$table_name = $wpdb->prefix . "top_ten_daily";
|
18 |
+
|
19 |
+
$is_widget = intval($_GET['widget']);
|
20 |
+
|
21 |
+
$tptn_settings = tptn_read_options();
|
22 |
+
$limit = $tptn_settings['limit'];
|
23 |
+
$daily_range = $tptn_settings[daily_range]. ' DAY';
|
24 |
+
$current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $daily_range), INTERVAL 1 DAY) ");
|
25 |
+
|
26 |
+
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
|
27 |
+
$sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
28 |
+
if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
|
29 |
+
$sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' ";
|
30 |
+
$sql .= "GROUP BY postnumber ";
|
31 |
+
$sql .= "ORDER BY sumCount DESC LIMIT $limit";
|
32 |
+
|
33 |
+
$results = $wpdb->get_results($sql);
|
34 |
+
|
35 |
+
$output = '<div id="crp_related">';
|
36 |
+
if(!$is_widget) $output .= $tptn_settings['title_daily'];
|
37 |
+
$output .= '<ul>';
|
38 |
+
if ($results) {
|
39 |
+
foreach ($results as $result) {
|
40 |
+
$output .= '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>';
|
41 |
+
if ($tptn_settings['disp_list_count']) $output .= ' ('.$result->sumCount.')';
|
42 |
+
$output .= '</li>';
|
43 |
+
}
|
44 |
+
}
|
45 |
+
if ($tptn_settings['show_credit']) $output .= '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
|
46 |
+
$output .= '</ul>';
|
47 |
+
$output .= '</div>';
|
48 |
+
|
49 |
+
echo "document.write('".$output."')";
|
50 |
+
}
|
51 |
+
tptn_daily_lists();
|
52 |
+
?>
|
top-10.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Top 10
|
4 |
-
Version: 1.
|
5 |
Plugin URI: http://ajaydsouza.com/wordpress/plugins/top-10/
|
6 |
Description: Count daily and total visits per post and display the most popular posts based on the number of views. Based on the plugin by <a href="http://weblogtoolscollection.com">Mark Ghosh</a>. <a href="options-general.php?page=tptn_options">Configure...</a>
|
7 |
Author: Ajay D'Souza
|
@@ -18,7 +18,8 @@ if (!function_exists('add_action')) {
|
|
18 |
}
|
19 |
}
|
20 |
|
21 |
-
$tptn_db_version
|
|
|
22 |
|
23 |
function ald_tptn_init() {
|
24 |
load_plugin_textdomain('myald_tptn_plugin', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)));
|
@@ -92,7 +93,9 @@ function tptn_show_pop_posts() {
|
|
92 |
echo '<ul>';
|
93 |
if ($results) {
|
94 |
foreach ($results as $result) {
|
95 |
-
echo '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>
|
|
|
|
|
96 |
}
|
97 |
}
|
98 |
if ($tptn_settings['show_credit']) echo '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
|
@@ -107,24 +110,36 @@ function tptn_show_daily_pop_posts() {
|
|
107 |
$tptn_settings = tptn_read_options();
|
108 |
$limit = $tptn_settings['limit'];
|
109 |
|
110 |
-
$
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
}
|
|
|
|
|
|
|
124 |
}
|
125 |
-
|
126 |
-
echo '</ul>';
|
127 |
-
echo '</div>';
|
128 |
}
|
129 |
|
130 |
// Default Options
|
@@ -138,10 +153,13 @@ function tptn_default_options() {
|
|
138 |
exclude_pages => true, // Exclude Pages
|
139 |
track_authors => false, // Track Authors visits
|
140 |
pv_in_admin => true, // Add an extra column on edit posts/pages to display page views?
|
|
|
|
|
141 |
count_disp_form => '(Visited %totalcount% times, %dailycount% visits today)', // Format to display the count
|
142 |
title => $title, // Title of Popular Posts
|
143 |
title_daily => $title_daily, // Title of Daily Popular
|
144 |
limit => '10', // How many posts to display?
|
|
|
145 |
);
|
146 |
return $tptn_settings;
|
147 |
}
|
@@ -204,6 +222,7 @@ function tptn_install() {
|
|
204 |
accessedid int NOT NULL AUTO_INCREMENT,
|
205 |
postnumber int NOT NULL,
|
206 |
cntaccess int NOT NULL,
|
|
|
207 |
PRIMARY KEY (accessedid)
|
208 |
);";
|
209 |
|
@@ -227,11 +246,15 @@ function tptn_install() {
|
|
227 |
|
228 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
229 |
dbDelta($sql);
|
230 |
-
|
|
|
|
|
|
|
231 |
$sql = "CREATE TABLE " . $table_name_daily . " (
|
232 |
accessedid int NOT NULL AUTO_INCREMENT,
|
233 |
postnumber int NOT NULL,
|
234 |
cntaccess int NOT NULL,
|
|
|
235 |
PRIMARY KEY (accessedid)
|
236 |
);";
|
237 |
|
@@ -244,71 +267,70 @@ function tptn_install() {
|
|
244 |
}
|
245 |
if (function_exists('register_activation_hook')) {
|
246 |
register_activation_hook(__FILE__,'tptn_install');
|
247 |
-
register_activation_hook(__FILE__, 'tptn_cron_install');
|
248 |
}
|
249 |
|
250 |
-
|
251 |
-
|
252 |
-
function
|
253 |
-
if (!wp_next_scheduled('tptn_cron_hook')) {
|
254 |
-
wp_schedule_event(mktime(0,0), 'daily', 'tptn_cron_hook');
|
255 |
-
}
|
256 |
-
}
|
257 |
-
function tptn_daily_clean() {
|
258 |
global $wpdb;
|
259 |
-
$table_name_daily = $wpdb->prefix . "
|
260 |
|
261 |
$sql = "TRUNCATE TABLE $table_name_daily";
|
262 |
$wpdb->query($sql);
|
263 |
}
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
}
|
268 |
-
function tptn_cron_deinstall() {
|
269 |
-
wp_clear_scheduled_hook('tptn_cron_hook');
|
270 |
-
}
|
271 |
-
|
272 |
-
// Create a WordPress Widget for Popular Posts
|
273 |
-
function widget_tptn_pop($args) {
|
274 |
global $wpdb, $siteurl, $tableposts, $id;
|
275 |
|
276 |
extract($args); // extracts before_widget,before_title,after_title,after_widget
|
277 |
|
278 |
-
$table_name = $wpdb->prefix . "
|
279 |
$tptn_settings = tptn_read_options();
|
280 |
$limit = $tptn_settings['limit'];
|
281 |
|
282 |
-
$
|
283 |
-
$sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
284 |
-
if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
|
285 |
-
$sql .= "ORDER BY cntaccess DESC LIMIT $limit";
|
286 |
-
|
287 |
-
$results = $wpdb->get_results($sql);
|
288 |
-
|
289 |
-
$title = (($tptn_settings['title']) ? strip_tags($tptn_settings['title']) : __('Popular Posts'));
|
290 |
-
|
291 |
echo $before_widget;
|
292 |
echo $before_title.$title.$after_title;
|
293 |
-
|
294 |
-
if ($
|
295 |
-
|
296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
}
|
|
|
|
|
298 |
}
|
299 |
-
|
300 |
-
echo '</ul>';
|
301 |
-
|
302 |
echo $after_widget;
|
303 |
}
|
304 |
|
305 |
-
// Create a WordPress Widget for
|
306 |
-
function
|
307 |
global $wpdb, $siteurl, $tableposts, $id;
|
308 |
|
309 |
extract($args); // extracts before_widget,before_title,after_title,after_widget
|
310 |
|
311 |
-
$table_name = $wpdb->prefix . "
|
312 |
$tptn_settings = tptn_read_options();
|
313 |
$limit = $tptn_settings['limit'];
|
314 |
|
@@ -319,14 +341,16 @@ function widget_tptn_pop_daily($args) {
|
|
319 |
|
320 |
$results = $wpdb->get_results($sql);
|
321 |
|
322 |
-
$title = (($tptn_settings['
|
323 |
|
324 |
echo $before_widget;
|
325 |
echo $before_title.$title.$after_title;
|
326 |
echo '<ul>';
|
327 |
if ($results) {
|
328 |
foreach ($results as $result) {
|
329 |
-
echo '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>
|
|
|
|
|
330 |
}
|
331 |
}
|
332 |
if ($tptn_settings['show_credit']) echo '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Top 10
|
4 |
+
Version: 1.3
|
5 |
Plugin URI: http://ajaydsouza.com/wordpress/plugins/top-10/
|
6 |
Description: Count daily and total visits per post and display the most popular posts based on the number of views. Based on the plugin by <a href="http://weblogtoolscollection.com">Mark Ghosh</a>. <a href="options-general.php?page=tptn_options">Configure...</a>
|
7 |
Author: Ajay D'Souza
|
18 |
}
|
19 |
}
|
20 |
|
21 |
+
global $tptn_db_version;
|
22 |
+
$tptn_db_version = "2.8";
|
23 |
|
24 |
function ald_tptn_init() {
|
25 |
load_plugin_textdomain('myald_tptn_plugin', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)));
|
93 |
echo '<ul>';
|
94 |
if ($results) {
|
95 |
foreach ($results as $result) {
|
96 |
+
echo '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>';
|
97 |
+
if ($tptn_settings['disp_list_count']) echo ' ('.$result->cntaccess.')';
|
98 |
+
echo '</li>';
|
99 |
}
|
100 |
}
|
101 |
if ($tptn_settings['show_credit']) echo '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
|
110 |
$tptn_settings = tptn_read_options();
|
111 |
$limit = $tptn_settings['limit'];
|
112 |
|
113 |
+
$output = '';
|
114 |
+
if ($tptn_settings['d_use_js']) {
|
115 |
+
$output .= '<script type="text/javascript" src="'.get_bloginfo('wpurl').'/wp-content/plugins/top-10/top-10-daily.js.php"></script>';
|
116 |
+
} else {
|
117 |
+
$daily_range = $tptn_settings[daily_range]. ' DAY';
|
118 |
+
$current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $daily_range), INTERVAL 1 DAY) ");
|
119 |
+
|
120 |
+
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
|
121 |
+
$sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
122 |
+
if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
|
123 |
+
$sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' ";
|
124 |
+
$sql .= "GROUP BY postnumber ";
|
125 |
+
$sql .= "ORDER BY sumCount DESC LIMIT $limit";
|
126 |
+
|
127 |
+
$results = $wpdb->get_results($sql);
|
128 |
+
|
129 |
+
$output .= '<div id="crp_related">'.$tptn_settings['title_daily'];
|
130 |
+
$output .= '<ul>';
|
131 |
+
if ($results) {
|
132 |
+
foreach ($results as $result) {
|
133 |
+
$output .= '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>';
|
134 |
+
if ($tptn_settings['disp_list_count']) $output .= ' ('.$result->sumCount.')';
|
135 |
+
$output .= '</li>';
|
136 |
+
}
|
137 |
}
|
138 |
+
if ($tptn_settings['show_credit']) $output .= '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
|
139 |
+
$output .= '</ul>';
|
140 |
+
$output .= '</div>';
|
141 |
}
|
142 |
+
echo $output;
|
|
|
|
|
143 |
}
|
144 |
|
145 |
// Default Options
|
153 |
exclude_pages => true, // Exclude Pages
|
154 |
track_authors => false, // Track Authors visits
|
155 |
pv_in_admin => true, // Add an extra column on edit posts/pages to display page views?
|
156 |
+
disp_list_count => true, // Display count in popular lists?
|
157 |
+
d_use_js => false, // Use JavaScript for displaying daily posts
|
158 |
count_disp_form => '(Visited %totalcount% times, %dailycount% visits today)', // Format to display the count
|
159 |
title => $title, // Title of Popular Posts
|
160 |
title_daily => $title_daily, // Title of Daily Popular
|
161 |
limit => '10', // How many posts to display?
|
162 |
+
daily_range => '1', // Daily Popular will contain posts of how many days?
|
163 |
);
|
164 |
return $tptn_settings;
|
165 |
}
|
222 |
accessedid int NOT NULL AUTO_INCREMENT,
|
223 |
postnumber int NOT NULL,
|
224 |
cntaccess int NOT NULL,
|
225 |
+
dp_date date NOT NULL,
|
226 |
PRIMARY KEY (accessedid)
|
227 |
);";
|
228 |
|
246 |
|
247 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
248 |
dbDelta($sql);
|
249 |
+
|
250 |
+
$sql = "DROP TABLE $table_name_daily";
|
251 |
+
$wpdb->query($sql);
|
252 |
+
|
253 |
$sql = "CREATE TABLE " . $table_name_daily . " (
|
254 |
accessedid int NOT NULL AUTO_INCREMENT,
|
255 |
postnumber int NOT NULL,
|
256 |
cntaccess int NOT NULL,
|
257 |
+
dp_date date NOT NULL,
|
258 |
PRIMARY KEY (accessedid)
|
259 |
);";
|
260 |
|
267 |
}
|
268 |
if (function_exists('register_activation_hook')) {
|
269 |
register_activation_hook(__FILE__,'tptn_install');
|
270 |
+
//register_activation_hook(__FILE__, 'tptn_cron_install');
|
271 |
}
|
272 |
|
273 |
+
|
274 |
+
// Function to delete all rows in the daily posts table
|
275 |
+
function tptn_trunc_count() {
|
|
|
|
|
|
|
|
|
|
|
276 |
global $wpdb;
|
277 |
+
$table_name_daily = $wpdb->prefix . "top_ten_daily";
|
278 |
|
279 |
$sql = "TRUNCATE TABLE $table_name_daily";
|
280 |
$wpdb->query($sql);
|
281 |
}
|
282 |
|
283 |
+
// Create a WordPress Widget for Daily Popular Posts
|
284 |
+
function widget_tptn_pop_daily($args) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
global $wpdb, $siteurl, $tableposts, $id;
|
286 |
|
287 |
extract($args); // extracts before_widget,before_title,after_title,after_widget
|
288 |
|
289 |
+
$table_name = $wpdb->prefix . "top_ten_daily";
|
290 |
$tptn_settings = tptn_read_options();
|
291 |
$limit = $tptn_settings['limit'];
|
292 |
|
293 |
+
$title = (($tptn_settings['title_daily']) ? strip_tags($tptn_settings['title_daily']) : __('Daily Popular'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
echo $before_widget;
|
295 |
echo $before_title.$title.$after_title;
|
296 |
+
|
297 |
+
if ($tptn_settings['d_use_js']) {
|
298 |
+
echo '<script type="text/javascript" src="'.get_bloginfo('wpurl').'/wp-content/plugins/top-10/top-10-daily.js.php?widget=1"></script>';
|
299 |
+
} else {
|
300 |
+
$daily_range = $tptn_settings[daily_range]. ' DAY';
|
301 |
+
$current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $daily_range), INTERVAL 1 DAY) ");
|
302 |
+
|
303 |
+
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
|
304 |
+
$sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
|
305 |
+
if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
|
306 |
+
$sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' ";
|
307 |
+
$sql .= "GROUP BY postnumber ";
|
308 |
+
$sql .= "ORDER BY sumCount DESC LIMIT $limit";
|
309 |
+
|
310 |
+
$results = $wpdb->get_results($sql);
|
311 |
+
|
312 |
+
echo '<ul>';
|
313 |
+
if ($results) {
|
314 |
+
foreach ($results as $result) {
|
315 |
+
echo '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>';
|
316 |
+
if ($tptn_settings['disp_list_count']) echo ' ('.$result->sumCount.')';
|
317 |
+
echo '</li>';
|
318 |
+
}
|
319 |
}
|
320 |
+
if ($tptn_settings['show_credit']) echo '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
|
321 |
+
echo '</ul>';
|
322 |
}
|
323 |
+
|
|
|
|
|
324 |
echo $after_widget;
|
325 |
}
|
326 |
|
327 |
+
// Create a WordPress Widget for Popular Posts
|
328 |
+
function widget_tptn_pop($args) {
|
329 |
global $wpdb, $siteurl, $tableposts, $id;
|
330 |
|
331 |
extract($args); // extracts before_widget,before_title,after_title,after_widget
|
332 |
|
333 |
+
$table_name = $wpdb->prefix . "top_ten";
|
334 |
$tptn_settings = tptn_read_options();
|
335 |
$limit = $tptn_settings['limit'];
|
336 |
|
341 |
|
342 |
$results = $wpdb->get_results($sql);
|
343 |
|
344 |
+
$title = (($tptn_settings['title']) ? strip_tags($tptn_settings['title']) : __('Popular Posts'));
|
345 |
|
346 |
echo $before_widget;
|
347 |
echo $before_title.$title.$after_title;
|
348 |
echo '<ul>';
|
349 |
if ($results) {
|
350 |
foreach ($results as $result) {
|
351 |
+
echo '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>';
|
352 |
+
if ($tptn_settings['disp_list_count']) echo ' ('.$result->cntaccess.')';
|
353 |
+
echo '</li>';
|
354 |
}
|
355 |
}
|
356 |
if ($tptn_settings['show_credit']) echo '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
|