Many sites that use a certain popularity rating do this using a standard algorithm to determine the rating, and then fade out forever over time. What I found works better for sites with less traffic - this is a multiplier that gives a bonus to new content / activity - it is essentially the same, but the rating stops changing after a certain period of time.
For example, here is a pseudo example of what you can try. Of course, you will need to adjust how much weight you assign to each category based on your own experience with your site. Comments are rare, but take more effort from the user than favorites / voice, so they probably should gain more weight.
score = (votes / 10) + comments age = UNIX_TIMESTAMP() - UNIX_TIMESTAMP(date_created) if(age < 86400) score = score * 1.5
This type of approach will give a bonus to new content uploaded on the last day. If you would like to approach this in a similar way only for content that has been recently selected or commented on, you can simply add some WHERE constraints to your query that grab the rating from the database.
In fact, there are two big reasons for not counting this rating on the fly.
- The requirement that your database retrieves all this data and performs calculations on each page load only to reorder the items leads to an expensive query.
- Probably smaller production, but if you have a relatively small amount of activity on the site, small changes in the ranking can lead to a significant movement of content.
This gives you either a caching of results periodically, or setting up a cron job to update a new database column that has this rating.
source share