madebyraygun / trending-posts

Trending Posts for Craft CMS 3 tracks pageviews over time and orders posts by popularity on the front-end.
MIT License
6 stars 3 forks source link

orderBy("popular") excludes entries with zero views #11

Open daveyjones opened 5 years ago

daveyjones commented 5 years ago

This plugin is awesome! My only trouble was that right after installing, adding orderBy("popular") to my queries was causing empty results, since all entries had zero views. I had over 1,000 entries, so to fix this I wrote a script to populate each entry with 1 view. However, it would be really nice if orderBy("popular") included entries with zero views.

daltonrooney commented 5 years ago

Hey, thanks for the feedback! I'm not sure this would be possible the way the plugin is currently architected though. In order to determine popularity, an additional table is created which keeps tracks of views. This table is only populated when the {% do craft.trendingPosts.increment(entry.id) %} variable is run on an entry, so on first run it makes sense that it would return no entries. I think your script may be the best solution for a new install.

I'm curious to know more about your use case where you need to update every post, though -- this plugin was originally conceived to create a trending sidebar for a news site... kind of like you would find on NYTimes or Buzzfeed. Maybe returning 10 - 15 entries at most. Are you trying to sort your entire site by popularity?

daveyjones commented 5 years ago

@daltonrooney Thanks for the response! Yeah this isn't a super important feature—my script solves the issue—but I'd be happy to provide a bit more context. I'm building an online product catalog. On each product page, I need to show the most popular related products in the same category as the current product. So it's the same idea as a trending sidebar, but I just have one for every category. My issue was that I wanted these related sections populated on day 1 without having to wait for traffic to populate them organically.