The WP-PostViews plug-in shows how to set the time for the popular article

Do not know for what reason, 1.30 after the WP-PostViews plugin canceled the original existence of the get_timespan_most_viewed function, which is also recently learned on the Internet, because recently have the mood to modify the theme, plug-in, find kid’s blog above this plugin provides small Tools in the sidebar display content is not how to change a few months, the reason is very simple, set up is the most browsing articles, more and more more and more, so I would like to modify the display settings, unfortunately the background is not related settings, although There is the nearest, but it seems that I am not the result.
Baidu for a while to know the original plug this function, and now there is no, but some people share the previous function on the Internet, so much simpler. Copy the following function to the wp-postviews.php file anywhere (of course, to the appropriate point of any place, do not put other functions in the middle ok).
function get_timespan_most_viewed ($ mode = ”, $ limit = 20, $ days = 1, $ display = true) {
global $ wpdb, $ post;
$ limit_date = current_time (‘timestamp’) – ($ days * 86400);
$ limit_date = date (“Y-m-d H: i: s”, $ limit_date);
$ where = ”;
$ temp = ”;
if (! empty ($ mode) && $ mode! = ‘both’) {
$ where = “post_type = ‘$ mode'”;
} else {
$ where = ‘1 = 1’;
}
$ most_viewed = $ wpdb-> get_results (“SELECT DISTINCT $ wpdb-> posts. *, (meta_value + 0) AS views FROM $ wpdb-> posts LEFT JOIN $ wpdb-> postmeta ON $ wpdb-> postmeta.post_id = $ “AND AND meta_keyword = ‘ideas’ AND post_password = ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ORDER BY views DESC LIMIT $ limit ‘);
if ($ most_viewed) {
foreach ($ most_viewed as $ post) {
$ post_title = get_the_title ();
$ post_views = intval ($ post-> views);
$ post_views = number_format ($ post_views);
$ temp. = “<li> <a href=\””.get_permalink().”\”> $ post_title </a> – $ post_views” .__ (‘views’, ‘wp-postviews’). < / li> “;
}
} else {
$ temp = ‘<li>’ .__ (‘N / A’, ‘wp-postviews’). ‘</ li>’. \ n “;
}
if ($ display) {
echo $ temp;
} else {
return $ temp;
}
}
Just put the above statement is still not work, although many blogs that can, may all think that write blog language? Although I can change, but the boy think that for those who do not understand why php novice, it is really harder and harder ah.
Here kid for everyone to sort out the next, for everyone to share.
case ‘least_viewed’:
get_least_viewed ($ mode, $ limit, $ chars);
break
Very simple, open the wp-postviews.php file in the ### Function: Display Least Viewed Page / Post or other functions above the above function, once again, the function to add location, but as far as possible with other business functions put together, Easy to analyze it! After the operation is the small tool options Statistics Type add get_timespan_most_viewed option, this directly in the wp-postviews.php file search Statistics Type, you can see
<$ php_e (‘Least Viewed’, ‘wp-postviews’);?> </ option>
Or the contents of other options, copy a line, paste to the top or below (of course, can also be the middle), and then the above statement least_viewed or other copy of the statement you change the value to get_timespan_most_viewed, so complete the background operation, But the current choice of this option is not displayed after the sidebar, because the output of the place to improve, the next step is also in the wp-postviews.php file operation, search class WP_Widget_PostViews, function widget function to find the switch statement, which should have Four turns, shaped like
case ‘least_viewed’:
get_least_viewed ($ mode, $ limit, $ chars);
break
Do not want to re-copy a copy of the location to the parallel, will least_viewed modified to get_timespan_most_viewed, so back to the first page refresh, the display should be a hot day, because the function is the default (the original function is the default 30 days, Set to 1 day), there is no option in the background, there is a need to modify the function of their own data can be.
In addition, the point is that the above provided get_timespan_most_viewed function is the old version of the function, does not support the current version of the output format, etc., where the kid and according to the new variable definition of the following functions, you can directly replace the above provided The get_timespan_most_viewed function is used, the function body is as follows
$ where = “post_type = ‘$ mode'”;
} else {
$ where = ‘1 = 1’;
}
$ most_viewed = $ wpdb-> get_results (“SELECT DISTINCT $ wpdb-> posts. *, (meta_value + 0) AS views FROM $ wpdb-> posts LEFT JOIN $ wpdb-> postmeta ON $ wpdb-> postmeta.post_id = $ “AND AND meta_keyword = ‘ideas’ AND post_password = ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ” ORDER BY views DESC LIMIT $ limit ‘);
if ($ most_viewed) {
foreach ($ most_viewed as $ post) {
$ post_views = intval ($ post-> views);
$ post_title = get_the_title ($ post);
if ($ chars> 0) {
$ post_title = snippet_text ($ post_title, $ chars);
}
$ post_excerpt = views_post_excerpt ($ post-> post_excerpt, $ post-> post_content, $ post-> post_password, $ chars);
$ temp = stripslashes ($ views_options [‘most_viewed_template’]);
$ temp = str_replace (“% VIEW_COUNT%”, number_format_i18n ($ post_views), $ temp);
$ temp = str_replace (“% POST_TITLE%”, $ post_title, $ temp);
$ temp = str_replace (“% POST_EXCERPT%”, $ post_excerpt, $ temp);
$ temp = str_replace (“% POST_CONTENT%”, $ post-> post_content, $ temp);
$ temp = str_replace (“% POST_URL%”, get_permalink ($ post), $ temp);
$ output. = $ temp;
}
} else {
$ output = ‘<li>’ .__ (‘N / A’, ‘wp-postviews’). ‘</ li>’. \ n “;
}
if ($ display) {
echo $ output;
} else {
return $ output;
}
}
}
As shown in the function parameters, set the number of days has been marked with the note, where is still no longer provide the option to set the panel, the need for friends can own toss, kid in the debugging time may be because the day visit is too low, set 1 day Can not achieve the desired display, set back to 30 days, we can set according to need.