WordPress Plugin: Daily Top 10 Posts

If you want to know how much hits your posts are receiving on a daily basis, then the Daily Top 10 Posts plugin is for you. What it does is track the hits of each blog post for the current day and cumulatively at the same time. You may also display sidebar widgets containing a list of the most popular posts for the day and most popular posts overall.

Plugin Name: Daily Top 10 Posts
Description: Tracks the number of pageviews per blog post for the current day and cumulatively with options to display sidebar widgets for both.
Author: Andrew dela Serna
Version: 0.7
Notice: Compatible with WordPress 2.7-2.8.
Disclaimer: This is a standalone plugin. If you have been using the Top 10 plugin, please be advised that using the Daily Top 10 Posts plugin means your pageviews will start from zilch.

INSTALLATION
————
1A. WordPress 2.7-2.8 users, download the plugin from http://www.alleba.com/blog/wp-downloads/dailytop10.zip
1B. WordPress 2.6 and below users, download the plugin from http://www.alleba.com/blog/wp-downloads/dailytop10.zip
2. Extract and upload dailytop10.php to 'yourserver.com/wp-content/plugins/'
3. Login to your WordPress admin panel and browse to the Plugins section.
4. Activate The Daily Top 10 Posts plugin.

INSTRUCTIONS
————
1. Go to Admin Panel > Design > Theme Editor and click on Single Post (single.php).

#Find this line:

<?php the_time('F jS, Y') ?> //date

#Right after it, insert this line:
<br /><?php if (function_exists('todays_overall_count')) { todays_overall_count($post->ID, 'Visited', 'times', 'so far today', '0', 'show'); } ?>

#The line will display something like “Visited 300 times, 25 so far today” while viewing an individual post.
#You may edit the wording to suit your preference.
#If you wish to leave a word/phrase empty, use two quotes '' instead of just leaving it completely blank.
#Insert only one instance of this line to avoid double tracking.
#Change '0' to '1' if you wish to track unique sessions.
#Change 'show' to 'noshow' if you donot wish to display the post count information.

2. To display the number of views per post on the main index page, click on Main Index Template (index.php) in the Theme Editor panel.

#Find this line:

<?php the_time('F jS, Y') ?>

#Right after it, insert this line:

<br /><?php if (function_exists('todays_overall_main')) { todays_overall_main($post->ID, 'Viewed', 'times', 'so far today'); } ?>

#The line will display something like “Visited 300 times, 25 so far today” under each post heading
#while browsing your main page.
#You may edit the wording to suit your preference.
#If you wish to leave a word/phrase empty, use two quotes '' instead of just leaving it completely blank.

3. To add the sidebar widget, you may add it directly in the widgets panel of your theme (Design > Widgets). If your theme is not widget-ready, click on sidebar.php in the Theme Editor panel and do the following:

#Add the following code:

<h3>Top Posts for Today</h3>
<?php if (function_exists('todays_count_widget')) { todays_count_widget('views', 'ul'); }?>

#You may edit the word “views” to your liking (e.g. visits, pageviews or leave it empty '').
#The list format defaults to an unordered list (ul). If you would like an ordered list, change it to 'ol'.

4. To add the sidebar widget to show your most popular posts overall, you may add it directly in the widgets panel of your theme (Design > Widgets). If your theme is not widget-ready, click on sidebar.php in the Theme Editor panel and do the following:
#Add the following code:

<h3>Overall Top Posts</h3>
<?php if (function_exists('todays_overall_count_widget')) { todays_overall_count_widget('views', 'ul'); } ?>

#You may edit the word “views” to your liking (e.g. visits, pageviews or leave it empty '').
#The list format defaults to an unordered list (ul). If you would like an ordered list, change it to 'ol'.

Update: Now has the ability to track unique hits based on sessions. See instruction #1 for implementation.

0.2 Update: A serious flaw has been found that prevents the daily count from incrementing. Please download the latest version to correct this.

0.3 Update: Numerous bugs corrected. For more, read this post.

0.4 Update: Numerous bugs corrected. Added support for widgets. For more, read this post.

0.5 Update: Bugs in WordPress 2.7 corrected. Check this post.

0.6 Update: CSS bugs in WordPress 2.7 corrected. Check this post.

0.7 Update: Ability to exclude posts added. Tested to work on WordPress 2.8 Check this post.

As always, I am open to your comments and suggestions. I hope you like this one! Thanks!

276 comments

  1. Great plugin. Is it possible to add a function which only displays todays count. I use another plugin for today counts and don’t want to loose that count. I’ve tinkered with the code to modify the “todays_overall_count” function to only display todays count.

    Regards

  2. i’ll give this a try, drew! i was actually wondering about yuga’s views counter sometime ago. thanks for this!

  3. Hi there! I think this is a great plugin but I’m having trouble inserting the widget into my sidebar. Can you help please? Thanks!

  4. @Josette: I see that you have two sidebars. Just go to Presentation > Theme Editor and click on the appropriate sidebar file where you will insert the widget code.

  5. I’m sorry. I’m not sure if you were able to see this code in my previous comment!


    {Box Title here}

    {your content here}

  6. @tricky: It already works that way. Please read the entire post to find out how.

    @Josette: Yes that’s exactly how you should insert it. Are you on Firefox? The instructions above don’t appear correctly in IE. Better if you read the readme.txt file included in the download.

  7. @Jeff Freeman: I’ve come up with something that comes close to that, although it depends on sessions. I’m still testing it. I’ll release it when it’s stable.

  8. Hi. We sent you the e-Ticket for the Philippine Blog Awards 2007. Please show this at the registration table. You will then be given two entrance tickets: one for you and another for your guest. If you have not received your e-Ticket or have any questions please email philippineblogawards [at] gmail [dot] com. Best of luck to you and your blog. See you there!

  9. your plugin has bug.

    this function is error:

    function todays_date()

    and, i replaced all code on this function below:

    function todays_date() {

    $cdate = date(‘Y-m-d’);
    return $cdate;
    }

    i worked.

    this plugin will not work with 04-02-2007 (m-d-Y).

    http://www.woim.net

  10. Cool plugin! Too bad I can’t use it since I’ve been using the Top 10 plugin for quite a while now. Anyways, good job! Looking forward to other upcoming plugins from you. 🙂

  11. Hi,

    First, I wanted to thank you for this plugin.

    It’s all working great except for the single.php file.

    When you visit a post for the first time, you get this error :

    Warning: Missing argument 2 for todays_count() in wp-content/plugins/dailytop10.php on line 164

    Any help ?
    Thanks

  12. @hoaihung: Thanks! That was among the errors that I already fixed.

    @Jaypee: I’ll come up with something that will still allow you to keep the old plugin.

    @Richard: I’ll look into that error. Check back for updates on that.

  13. That’s a nice plug-in. Daily Top 10 Posts plugin gives information about readers. I found that there a lot lot of site analysis software, but I haven’t found a really great blog-oriented anaylysis software. I am gonna download this, hope it will be the great plugin.

  14. I get the same warnings that Richard gets, but only on the first time a blog post is accessed. After that it works fine. Looks like a problem when there are no recorded views?

    Nice plugin, though!

  15. Is it possible to offset the “todays_date” function so that blogs hosted at a different time zone can have the daily count reset at the users time zone.

    My blog is hosted on a server in Dallas US, but I’m in Australia. My daily count resets at about 2.00pm my time which is 12.00am Dallas US time. (Not sure exactly of time zone difference but you get the drift of my problem).

    Any ideas on a solution?

    Gary O

  16. Andrew, First of thanks for the nice plugin, you can see my review post here.

    Is it possible for you to add additional functionality to this plugin to let it display over all top viewed posts & pages?

    Advice please.

    DG…
    http://www.ditii.com

  17. We are also experiencing the Richard’s issue.

    Note also that the sidebar widget does not seem to update unless todays_count_widget is used in the post. If we don’t have todays_count_widget in the post, the count does not seem to be updated.

  18. Hi,
    I like your plugin but experienced the same error that others noted when visiting a post for the first time.
    Warning: Missing argument 2 for todays_count() in wp-content/plugins/dailytop10.php on line 164

    To rectify this I modified your plugin as follows on line 164:
    // $show_today = todays_count($postnum);
    $show_today = todays_count($postnum, $unique);

    I also noticed another slight bug. If a post is deleted, it will still show up in the top ten lists even though it no longer exists. This is a problem for me, because I have users who may add a post and later delete it. I created the following lines to fix it.

    add_action(‘delete_post’, ‘removal_function’);
    function removal_function($postnum) {
    global $wpdb;
    global $table_name;
    global $table_name_all;
    if ($postnum) {
    $wpdb->query(“DELETE FROM $table_name WHERE postnum = ‘$postnum'”);
    $wpdb->query(“DELETE FROM $table_name_all WHERE postnum = ‘$postnum'”);
    }
    }

    Thanks!

  19. is it possible to display the “today’s views” top ten posts in the sidebar, but don’t display anything in the single page of each post?

    I tried it but seems not working ;(

  20. Andrew,

    The plugin looks like a winner. I installed it on obar.php. That shouldn’t be a problem should it? At this point it does not appear to be picking up the posts I click. Maybe when others do that will change. If possible, would you visit my blog to see if the display seems normal to you? It’s on the left just beneat pages. I inserted Step #4 from your instructions.

    Thanks,
    -Ryan

  21. This is a superb plugin – many thanks for that, and hope your allergies subside – suffering myself here while coding. 🙂

  22. Great plug-in. Up and running…just one thing. As mentioned in another post is there a way to stop displaying the number of views?

    The sidebar displays the ‘Overall Top Posts’ and would prefer only the title to display and eliminate the (NN views) part.

  23. Found the answer. In the dailytop10.php file there is this line of code:

    ($postcount views)\n”;

    Change to this:

    \n”;

  24. Great plugin!

    I have it installed in the sidebar of my blog (link in my name) – however I can’t get the “2 Views” to not show up in the sidebar. By default it looks like ‘Views’, I’ve set it to ‘”‘ and just about every other configuration I can, still can’t get the “2 Views” to not follow the link to the article. Please advise.

  25. Thank you for this plugin, in sidebar everything is fine, but I have an error on single.php:

    Warning: Missing argument 6 for todays_overall_count() in /home/hotceleb/public_html/wp-content/plugins/dailytop10.php on line 246

    Any idea how to solve this?

    Thanks,
    Rita

  26. I have the solution for the argument 6-Problem!

    The right tag mus have ,” after the ‘0’(sorry, I already translatet into german, but you can see it anyway):

    ID, ‘Insgesamt ‘, ‘mal besucht, davon heute’, ‘mal.’, ‘0’,”); ?>

  27. I have been using this plugin for a long time and it’s fantastic, nice work on it.

    However, I recently switched web hosts and they’re in a different time zone now. I am in New York state on Eastern time, the web host is in Utah on Mountain time. I cannot get the daily post counts to reset on Eastern time. Is the OFFSET variable supposed to be set according to the host or according to my location? I want them to reset on Eastern time. I have it at -5 for Eastern but they’re not resetting at the right time. What should it be set for?

  28. I have the OFFSET at -5 for Eastern time, but now I see it’s still resetting on Mountain time which is -7

    It appears the OFFSET isn’t functioning for me. I have 0.3 on a WordPress 2.3.1 installation.

  29. Ok just dropped by to say that I solved the “line 246” problem mentioned by others and the soltion is not what “rita” mentioned above. If you use the solution provided by “rita” above it will break you wordpress (undoing will fix it). The solution is very simple. In the readme file the code ends like this: [ ‘0’); ?> ] in single.php, but the actual code should end like this : [ ‘0, ‘show’); ?> ] the readme file doesn’t mention “show” part at the end. adding this fixes the problem. However the author did mention it on the above post ( which is barely readable as all single qoutations looks like &apos, I wonder how the author missed it). Anyways, I am thankfull for the script and to show my appreciation I had to show the solution to problem which I eblieve will affect everyone who is following the readme file.

    On a side note I would like to know how reliable is this plugin in terms of accurate hits count. The reason I am asking is because I am in the process of hiring writers for my blog network, whom I would like to pay by visit counts on their posts (ie 1000 views = $2, like gizmodo pays to it’s writers). It is important for me to have a full-proof view counting system so that the view-count cannot be artificially inflated to get paid more. yes I have changed the value from ‘0’ to ‘1’, to track unique sessions. Is that all I need to stop any scams?

    Thanks for any help and thanks again for the plugin.
    Have a nice day!

  30. Hi andrew, Thanks for willing to look into it for when you have time. I really appreciate it. Is there any way possible for me to contact you by e-mail? You see my whole project (because of it’s nature) depends on this custom script. Without this script (or something similar)I cannot go forward with my work. I am willing to compensate you financially, if you want for this work as soon as possible for you. Again, I know you are busy and I really appreciate it. Please drop me an e-mail or let me write to you.

    Thanks.

Leave a comment

Your email address will not be published. Required fields are marked *