This weekend when reading some WordPress blog i noticed that there was used some kind of entry popularity meter. Happens that there exist a special WordPress plugin for that.
And i thought "Wow! That's nice and i think many ColdFusion bloggers would like to have something similar.".
First i tried to find something similar in ColdFusion, but without any luck of course. Then i tried to find the description of the algorythm used, but again no luck.
So, my next thought was.. what a heck! why not just create something similar?
This said, after few minutes of thinking and a couple of other minutes writting the code (thanks to ColdFusion
), i am ready to present what i came to.
NOTE: This is just a prove of concept, so if anyone have ideas how to have it better, please share your thoughts.
Ok. First of all the idea.
As most popular, 100% popularity, is taken the entry with the biggest number of views. The popularity for all other entries is calculated in comparison with the most popular one. So, if the most popular entry have 100 views and other entry have 23 views, the last one will be considered to have 23% popularity.
Same is done based on comments number (100% popularity will have the entry with highest number of comments).
So... the result, for each entry, will look something like: 61% / 36% Popularity. Where 61% is the popularity based on the number of views and 36% is the popularity based on the number of comments.
And now the code based on 1ssBlog.
The following function will return a structure with 2 keys: one with the number of views for the most visited entry and other with the number of comments for the entry with most comments.
<cffunction name="getViewsComments" output="false" returntype="any">
<cfset var views_comments = StructNew()>
<cfset var getmaxviewscomments = "">
<!--- get the Max number of views and comments --->
<cfquery name="getMaxViewsComments" username="#application.dsnUsername#" password="#application.dsnPassword#" datasource="#application.dsn#">
Select Ma<img src="images/smiles/14.gif" border="0">views) as maxView, Ma<img src="images/smiles/14.gif" border="0">commentsNumb) as maxComments
From onessBlog_entries
Where is_active = 1
and posted <= GetDate()
</cfquery>
<cfset views_comments.views = Val(getMaxViewsComments.maxView)>
<cfset views_comments.comments = Val(getMaxViewsComments.maxComments)>
<cfreturn views_comments = "">
</cffunction>
And now the usage.
<!--- first csll the getViewsComments() function --->
<cfset viewscomments = application.funcObj.getViewsComments()>
<!--- and now show the result on the screen --->
#Round(100*Val(viewsNumb)/viewsComments.views)#% / #Round(100*Val(commentsNumb)/viewsComments.comments)#% Popularity
<!--- where viewsNumb is the number of views for the current entry and commentsNumb is the number of comments for the current entry --->
NOTE: The popularity meter will be included in the next 1ssBlog updater.
Please don't hesitate to comment.
Categories
| ColdFusion | 160 | [RSS] |
| Other | 99 | [RSS] |
| My Projects | 60 | [RSS] |
| Fun | 54 | [RSS] |
| SQL | 50 | [RSS] |
| Deals | 18 | [RSS] |
| RIA | 18 | [RSS] |
| 1ssBlog | 16 | [RSS] |
| cfSQLMaster | 12 | [RSS] |
| Caching | 8 | [RSS] |
| Profit | 8 | [RSS] |
| Transerfing | 6 | [RSS] |
| AJAX | 5 | [RSS] |
| cfHSSF | 5 | [RSS] |
| cfWatcher | 5 | [RSS] |
| JavaScript | 5 | [RSS] |
| Amazon | 4 | [RSS] |
| cfFirewall | 4 | [RSS] |
| jQuery | 3 | [RSS] |
| 1ssChat | 2 | [RSS] |
| Security | 2 | [RSS] |
| SEO | 2 | [RSS] |
| Adobe Air | 1 | [RSS] |
| jQuery Mobile | 1 | [RSS] |
| MMA | 1 | [RSS] |
My Sites
Recent Entries
Recent Comments
- Looking for advice
Ed Tabara said: thx guys [More] - Looking for advice
Andy Jarrett said: [bick] + [lee] [More] - Looking for advice
jd said: bick + lee [More] - Looking for advice
me said: bi+kli bi fom bin and cli from click [More] - Is your site still vulnerable to SQLi attacks?
Ed said: no problem at all :) [More]
Search
Open Source
Calendar
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 |
Tags Cloud
1ssblog
about
access
adobe
ajax
amazon
caching
cfhssf
cfsqlmaster
cfwatcher
coldfusion
data
deals
fun
jquery
list
moldova
mssql
my projects
optimization
other
over
performance
profit
ria
sites
sql
this
transerfing
your
Subscribe
Enter your email address to subscribe to this blog.
Adobe Feeds
- Save 15% on Adobe Software with Promotion Code, for 8 Days Only
- Finding a new webhost: WPEngine.com and the others…
- Christophe Coenraets On Backbone.js And PhoneGap
- Flex User Group 2012 Tour European Dates
- YUI Theater — Gonzalo Cordero: “Yahoo! Local Mobile Case Study” (33 min.)
- Envato Community Meetup 2012 in Kuala Lumpur: RSVP Now!
- 23 Feb: Design event in Antwerp
1ssBlog was created by Ed Tabara and is running version 1.1.



"var
Optional
A keyword. Does not take a value"
Similarly with your use of cfreturn, I've always seen it done as just: