Most Viewed Posts

0

I’m looking for a script that creates a list of the most viewed posts across all blogs on my site. I know this has been asked for many times before, but there still seems to be no good solution to what seems to be an easy problem to solve for someone with a good knowledge of php (not me!).

Given that the Post Indexer script has a table for post_hits can someone write a simple script that pulls the data from the site_posts table and order it by post_hits?

If this has already been done I apologise – I have used the search function but found nothing relevant.

  • drmike
    • DEV MAN’s Mascot

    We have one but current loss of laptop due to 2 yr old staying with me kind of f’ed all that up. Working off iPod and 60 minutes of library time a day on terminal. Clients come first during that time.

    One hint: bad idea to do straight counts as judge else you get lots of old posts in there as well. Better to include time period as well. Say last week:

  • Andrew
    • Champion of Loops

    Hiya,

    Look at the top of the post indexer plugin:

    $post_indexer_enable_hit_tracking = ‘0’; //Either ‘1’ or ‘0’ – resource heavy

    Just change that variable to ‘1’ and hits will be tracked. We don’t advertise the feature and it’s disabled by default because A) it’s really not the best way to track popular posts and B) we don’t really suggest running it on shared hosts which is what a lot of people have their wpmu sites on.

    Thanks,

    Andrew

  • GhostPool
    • Site Builder, Child of Zeus

    Thanks for the replies guys.

    I have enabled hit tracking in the post_indexer script and I can see they are being counted. My site will be moving to a dedicated server shortly – so a drain on resources shouldn’t be a problem.

    Why is it not the best way to track popular posts Andrew, if you take into account the time period as drmike suggests, surely it would return the most viewed posts in say the last week?

  • GhostPool
    • Site Builder, Child of Zeus

    Users will eventually figure out that the most popular posts are tracked by page hits.

    I don’t intend to hide the fact the most popular posts are tracked by hits – I was going to have a column of most viewed posts. I don’t see people abusing the system, especially since I expect thousands of visitors a day which will drown out anyone trying to abuse the system.

    In terms of coding could anyone help me out with this?

  • Andrew
    • Champion of Loops

    There shouldn’t be any duplicates. Are the rows identical? If not can you tell me which columns don’t match up?

    Have the duplicates always been created or have they just shown up since you enabled the hit tracking feature?

    Lastly, do you have any other plugins that perform an action when a post is saved?

    Thanks,

    Andrew

  • GhostPool
    • Site Builder, Child of Zeus

    I think I’ve discovered the problem, I also have the sitewide-tags plugin installed. It creates a duplicate of the posts and places it in the main admin blog so it displays on the front page.

    I like this script as it gives me the ability to include the author name, category and time since posting, which is not possible using the recent posts plugin as far as I can tell – or is it?

  • Andrew
    • Champion of Loops

    Hiya,

    I like this script as it gives me the ability to include the author name, category and time since posting, which is not possible using the recent posts plugin as far as I can tell – or is it?

    Which script are you referring to? sitewide-tags?

    Thanks,

    Andrew