Wordpress

Top Posts By Category plugin

Update: Version 1.3 RC1 is out. Changes and download can be found here.

Top Posts By Category Plugin is a fork of original M&M tpbc plugin updated to work with new WordPress 2.3 taxonomy system. Compatible up to WordPress 2.6:

Install:

  1. Copy tpbct.php file to wp-content/plugins
  2. Activate the plugin as usual.
  3. Manage Options going to Options->Top Posts or Settings->Top Posts on WordPress 2.6.

Upgrade:

From My previous version: Just overwritte tpbct.php file with new version on plugins folder.

From M&M version: Disable old tpbc, delete tpbc.php file from plugins folder and install the new version (note that filenames are different). Configuration options and old recolected posts stats will be conserved.

Release Notes:

1.2:

– Solved some compatibility sql bugs.
– Solved a bug that prevents to show the list when Top Comented Posts option was used.

1.0 – Miki’s version:

– Required changes to work with WordPress 2.3 taxonomy system.

Si t'ha agradat l'article pots convidar-me a una birra

Be Sociable, Share!

46 thoughts on “Top Posts By Category plugin

  1. Hey tiu, t’ho estás currant 😀 Potser faig algo semblant a la meva web, i potser faci servir la teva versió en un altre blog que estic muntant per una amiga.

    Que vaixi bé Miki =)

  2. I get a database error:

    WordPress database err
    or Column ‘term_taxonomy_id’ in on clause is ambiguous for query SELECT wp_term_
    taxonomy.term_taxonomy_id as cat_ID FROM wp_term_taxonomy INNER JOIN wp_term_rel
    ationships ON term_taxonomy_id = wp_term_relationships.term_taxonomy_id WHERE wp
    _term_taxonomy.taxonomy = ‘category’ AND wp_term_relationships.object_id = 96

  3. Hello Tim,
    It seems that we are using different MySQL versions.
    I’ve uploaded the zip file again. Can you try it and tell mi if works for you?

  4. Hi amar, thanks for use it 😉

    (Note that I’m not an english speaker, corrections are welcomed and gratified with a link in this post)

  5. Sorry Abel, but currently you can only group the top posts by category.
    Thanks for your interest, I’ll consider your request for future releases.

    Good news: I’m tested the plugin on WP 2.5 and it works good without modifications. Enjoy it!

  6. Hi Miki,

    Thanks for the update to this plugin! I used it on a different site before and liked it but couldn’t get it to work after upgrading to WP 2.3.

    I have installed it and added tpbc_list in the square brackets (didn’t want to add them here in case it adds something strange in your comments) to a page that I will post after the list builds for a about week, but it only lists a single post with all the site hits listed next to it. Any ideas?

    Thanks again.

  7. Hi patty,

    The plugin track posts reads when:

    if (is_single () && !is_page ())

    on the “shutdown” hook (when whole page is loaded), and only works with categories (not tags for now).

    You can try to deactivate and reactivate de plugin again and visit a single post page to see if the tracker counts the visit.

    Can you access your db and view how may records have the wpdbprefix_tpbc table?

    It’s a strange behaviour… If you have more feedback, please tell me and I will review all code this weekend.

    Thanks for use it !

  8. Installed this plugin on WordPress 2.3.3, activated and put tpbc_list() in my template (didn’t use full syntax in comment of course) and I get no error but nothing appears. Anyone had success on WP 2.3.3?

  9. Hi Kyle,

    Thanks for your feedback, I upgraded to plugin to solve a bug when the Top Commented Posts option was used.

    It works for me now on wp 2.3.3 and on wp 2.5 both fresh install.

  10. It will work when I show most commented posts, but only when the categories option is off. When it is on it will start showing posts as categories after the last true category.

    I have top commented posts showing but would like it be top viewed.

  11. Hello Shell,

    I’m sorry but I have tried all possible combinations and cannot reproduce it. Can you try some things and tell me the results?

    – Exact configuration options that are you using.

    – If you can acces your database, can you see the content of $prefix_tpbc table?

    – Can you try to put the template tag: < ?php tpbc_visits ('Visited Once', 'Visited % Times', $none = '');?> inside the loop to see if it is really tracking?

  12. I have the same problem as Shell. For me, it only works when:
    -I choose to use by most commented posts AND
    -When I choose to merge categories (meaning it doesn’t show when I choose to separate categories)

  13. Hello Clement,

    Can you try putting the template tag: < ?php tpbc_visits ('Visited Once', 'Visited % Times', $none = '');?> inside the loop and tell me if it is tracking?

    Can you also see your server’s error log?

    Some hosting servers have MySQL (queries/hour) or other limitations, and in this version there is no cache and the list is recalculated each time is rendered, so if you have a lot of categories it can do a lot of queries too and break your MySQL connection depending on your hosting configuration.

    I don’t think any other reason at this moment, because it’s working for me and I cannot reproduce your behaviour, sorry.

  14. Your plug-in is listing draft posts that I have not published yet. Isn’t there some simple way for the plugin to check if a post is published or draft?

    Since I have very few posts on my new blog, apparently previewing the post a couple times while editing is enough for a post to make the top ten.

    Using WP 2.6.

  15. You are right David, the tracker is added on the “shutdown” hook (when whole page is loaded), so if the hook is called by wordpress on previews, the plugin tracks it.

    But note that tpbc table has a unique key defined as:
    UNIQUE_KEY `post_id_date_unique` (`post_id`, `ip`, `date`), so it’s very strange that it counts couple of times the same post on the same day on the same matchine.

    Can you see the content of tpbc table before and after a preview (two or more previews) to see what is happening?

    I will see how to “drop” draft posts from top visualization but this will be tracked anyway (for now).

    Thanks for your appoinment David.

  16. Since I don’t yet have even ten posts on my new blog, even one view of the preview post is enough to get it on my top ten list of popular posts (so for the time being, I’ve shortened the list to equal as many posts as I have published). Also, I do edit over a period of days, so this may contribute to the counter as well.

    Anyway, as soon as I have ten posts or more, it won’t be an issue. It just sort of took me by surprise.

  17. Hello Saulo,

    I’m sorry but at this moment is not possible to exclude some categories by configuration.
    But if you know sql, you can modify the source code by yourself adding the convenient where clause’s on sql sentences.

  18. hey Miki,

    I’m having the same problem as Kyle (above), except I’m using WordPress 2.6.1. I’ve uploaded the plug-in, activated it and placed the tpbc_list() function call (with the php syntax) in a text widget in my sidebar. Is there something else I’m forgetting to do? Thanks for any assistance.

  19. Hi patorjk,

    I think that the text widget is only for “free text” not for execute php code inside.

    The function tpbc_list() is a template tag, so you must edit your template ( in most of cases is sidebar.php file ) and add the call to the function. For example you can put the call after or before this bloc of code of your template:


    Put the call here...
    < ?php tpbc_list() ?>
    < ?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    .....
    < ?php endif; ?>
    Or here
    < ?php tpbc_list() ?>

    Hope this helps

  20. Hey there,

    This is a great plugin but I am having trouble with it after updating to 2.6.2. Bloggingot.com or WordPressjedi.com are now not counting anything, and Wpjedi only shows one post. Strange!

  21. Hi Cyrus,

    Are you using some wordpress cache plugin ? If one, try to deactivate and see what happens.

    I never tested the plugin over a cache, but I’m sure that cannot work together because no php code are executed on html cached pages…

    Perhaps this comment can help you to figure out the solution: http://mnm.uib.es/gallir/wp-cache-2/#comment-6464

    Please, tell me if you are success, or tell me the cache plugin/version you are using to test by myself (but cannot promise nothing…)

  22. Actually, I am not using WP-Cache or SuperCache. The thing is, the plug-in was working fine before the latest WordPress update (2.6.2). You can check my other blog (http://www.bloggingot.com). Under popular posts, it shows numbers but they stand still.

  23. I ask you about the cache because your server response headers contains this: “Vary: Accept-Encoding”, tipically added by a cache or proxy systems (not necessari a wp plugin, can be other intermediaries as transparent proxies added by some ISP’s), while mine says: “Cache-Control: no-cache, must-revalidate, max-age=0”.

    Well, if not a cache issue, we need to trace the problem to get more info:
    The plugin has two main options. Most comented that are queried directly to WP database, and most visited (your config and mine) that first track’s the visit and then query tpbc table to show the top posts list.

    Let’s to start:
    – Ensure that you are using the last version (download it again and replace tpbct.php file if unsure)
    – Disable and enable the plugin again, once enabled a call to “tpbc_tracker” function is added to “shutdown” wp hook (it is, when the whole page is loaded).
    – Do a “select count(*) from wp_tpbc” (with your own table prefix)
    – Visit a single post (not pages)
    – Do the query again to see if there is a new record on this table. (note that it only inserts a new record if there is not other visit to the same post from the same ip on the same day).

    If there is not a new record you must verify your server’s logs to see what is happening because the function only executes an insert query. If there is no info, try to modify line 70 to change “$wpdb->show_errors = 0;” to “$wpdb->show_errors = 1;”
    and visit a single post again.

    The next step would be to check the returning list query, but I think this part is working fine because we can see the list.

  24. Hi Miki,

    Thanks for the detailed instructions. I finally managed to get the plug-in to work on all the sites by disabling it and enabling it again. Strange but it worked. On BloggingOT I had more trouble. What I did was empty the database and now it’s working. Out of curiosity, is there like a limit on the number of records you put in the tpbc table? I haven’t seen any in the code… But thanks very much. This is possibly the most useful plugin I have ever used 🙂

  25. Hi Cyrus,

    I’m happy to have helped you !
    You are right, there is no limit in table size at this moment. I note for future release… (I also have other improvements in mind, but any date…)

    And, thanks to you for use it 😉

  26. 🙂 By the way, my problem came back. I simply have no idea what’s happening. You said something about cache. I have no plug-in like wp-cache on. Could the problem with WP-Polls or things like that?

  27. Nooooo…

    I’m sorry but I cannot figure out what can be happening… I don’t think that can be a compatibility problem with other plugins but you can do the tedious job (I know) of disable / enable plugins to test it. You should debug the plugin in your envoirment by yourself.

    Another thing that you can try if your template(s) are calling the “wp_footer” is change the tracker to this wp hook. Just change the line 299 from: add_action (‘shutdown’, ‘tpbc_tracker’); to add_action (‘wp_footer’, ‘tpbc_tracker’); and disable/enable the plugin to install the function into this hook. Or you can also can play with priorities adding a third argument to the add_action, p.e. add_action(‘shutdown’, ‘tpbc_tracker’, 1); or add_action(‘shutdown’, ‘tpbc_tracker’, 1); (Note that plugin must be disabled/enabled each time you change this function. Priorities goes from 1 (first) to 10 (last)).

    Good luck !

  28. Thank you so much for making this awesome plugin compatible with the newer versions of wordpress. I wonder why so little attention is given to it though. Anyway, it works ALMOST perfectly for me except that the category names are on top of the wrong posts.

    I have it set up here. http://usws.isgreat.org/popular

    Thank you so much once again! 🙂

  29. Hi usws,

    I will release a new version on next days that solves this bug, and some other changes…

    By now you can change the line 154 from
    `t4`.`term_taxonomy_id` AS `cat_ID`
    to
    `t4`.`term_id` AS `cat_ID`

    (note this only works with your current configuration)

    The two id’s are different only when we have deleted some old category and then added a new one, so this bug was not detected before by myself…

  30. Uh, i’m gonna thank you here too! It works fine for me now.. I’m real grateful for your help and your willingness to kep this plugin alive. Kudos to you!!

  31. Thanks for your thanks Nathalie :),

    please consider to use the 1.3 RC1 release, that solves all reported bugs, and add’s some nice config options. The only think I espect to add to the 1.3 final release is a button to clean uninstall database entries of the plugin. Enjoy!

Comments are closed.