2

I'm working on a typical craft blog with articles. I know there is a plugin that was used to teach craft plugin development that tracks entry visit counts here:

https://straightupcraft.com/craft-plugins/entry-count

However, is there anyway to distinguish the visits made in the last 24 hours? The docs on this simple plugin doesn't talk about it. The logic would probably be take the view count now and subtract by the count from 24 hours ago. I'm guessing the view count might be a value in the mysql table that keeps getting updated. If each count is a row in the table then perhaps there are ways to just query the db for counts associated with an entry filtered by the time stamp. But I highly doubt thats how the plugin is implemented.

I also could use help tracking the posts with the highest upvotes using the upvote plugin:

https://straightupcraft.com/craft-plugins/upvote

I'm doing this to work out a trending logic. Trending posts are posts that have a combination of highest view count and upvotes in the last 24 hours.

1 Answer 1

2

It looks like the Entry Count plugin could potentially serve your needs, though you'd need to make a few changes for it to behave the way you want. Natively, it looks like the counts are just lumped together for each entry.

Upvote is perfect for checking recent votes! (Disclaimer: I'm the author of Upvote.)

With Upvote, you can see if an entry was voted on in the past 24 hours, simply by checking the craft_upvote_elementtallies.dateUpdated value in the database.

craft_upvote_elementtallies

If that's not detailed enough, you can enable the option to "Keep a detailed record of all votes". This gives you a vote-by-vote report of every single upvote/downvote ever cast. The detailed log is stored separately in the craft_upvote_votelog table.

craft_upvote_votelog

Warning: An unchecked craft_upvote_votelog table can grow rapidly, and quickly swell the size of your database. If you only need it to check up on recent votes, feel free to set a cron job to frequently delete old rows.

The craft_upvote_votelog table is not critical for the day-to-day operations of Upvote. It's more of a "nice to have" for rare situations which could benefit from it (like in your scenario).

4
  • with upvote, is there a way to query the db for all votes cast in the last 24 hours using twig and find out which entries the votes are associated with?
    – ChaiTea
    Commented May 4, 2017 at 5:05
  • Not with Twig directly, but it would be very easy to write a plugin to collect that information and make it available via Twig.
    – Lindsey D
    Commented May 4, 2017 at 5:06
  • ok I think I need to go learn craft plugin dev first since I've never done one before. Will circle back on this one. So are there php functions or classes that the upvote plugin exposes that can query vote within last 24 hours and the associated entries? Will they return as an associate arrays that I can then export into twig tags?
    – ChaiTea
    Commented May 4, 2017 at 6:20
  • We're starting to get a bit off topic from the original post... Feel free to email [email protected], or DM me on Craft Slack (@lindseydiloreto), and I'd be happy to answer any additional questions on Upvote!
    – Lindsey D
    Commented May 4, 2017 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.