Subsribe to our RSS

latest reactions

christian louboutin shoes
With that kind of traffic you want to ad …
Rahul Anand
Thanks for the nice post. It works for m …
Serkan
thx a lot! …
msb
Thanks for above solution.There is ano …
Lori S.
FYI, I was using this successfully in CF …

Use OpenDNS

mxna feeds

cfmailparam behaviour change in CF9.01ColdFusion Job Opportunity in Houston, TXFacial Recognition in 14 Lines Of ColdFusionColdFusion UPS PackageColdFusion Job Opportunity in Arlington, VAColdFusion Job Opportunity in San Diego, CASome ColdFusionBloggers.org GuidelinesColdFusion Positions In CaliforniaListChangeDelimsunix epoch with coldfusionQuery scripting bug in Coldfusion 9Scoth On The Rock 2011 Tickets on salefoursquareCFC updated to version 1.0, now includes ColdFusion return typeFramework One Birds of a Feather session at CFUnitedWhat makes you a good ColdFusion programmer?

All files are strictly confidential: all information is classified.
© Copyright 2002 - 2010 mximize.com.
All right reserved.

MXNA webfeed

Visit Carlos Gallupa

Get SEO keywords automatically from an article or page

I just finished a nice little function to get the "best" keywords for the page displayed in every website we build with our CMS. Below is an example, what you get is a list of the words that are mostly used in the given page and therefore the best to use as META keywords or tags in your page. At least if you like to be found on the contents of your page...

<cfsavecontent variable="txt">
A nice little piece of text with at least twice the word little in the text, and off course three times the word text ;-)
</cfsavecontent>

<cffunction name="getSEOWords" access="public" output="true">
    <cfargument name="content" required="true" type="string" />
    <cfset var lsStopWords = "stop wordlist in your language (google it)" />
    <cfset list = arrayToList(listToArray(REReplace(arguments.content, "[[:space:]]{2,}"," ", "all" ), " ")) />
    <cfset var stWords = structNew() />
    <cfset var lsTop = "" />
    <cfset var aSort = arrayNew(1) />
   
    <!--- Get a unique structure of words counted --->
    <cfloop list="#list#" index="value">
        <cfif !listFindNoCase(lsStopWords, value) && !isNumeric(value)>
            <cfset value = trim(value) />
            <cfif structKeyExists(stWords, value)>
                <cfset stWords[value] = stWords[value] + 1 />
            <cfelse>
                <cfset stWords[value] = 1 />
            </cfif>
        </cfif>
    </cfloop>
   
    <!--- Order the structure with words, first keys are the words with the most counts --->
    <cfset aSort = structSort(stWords, "numeric", "desc") />
   
    <!--- Get the first 15 words from the list, if the count is more than one. --->
    <cfloop from="1" to="15" index="i">
        <cfif stWords[aSort[i]] GT 1>
            <cfset lsTop = listAppend(lsTop, aSort[i]) />
        </cfif>
    </cfloop>

    <cfreturn lsTop />
</cffunction>

<cfoutput>
    #getSEOWords(txt)#
</cfoutput>

3569 viewed | 6 opinion(s)  | del.icio.us | Digg it | Tjarko @ 13/10/09 17:19 cet


Reactions:

Darren Walker wrote.... (mail)

Instead of just judging keywords by counting, why not use the Yahoo term extractor API (http://developer.yahoo.com/search/content/V1/termExtraction.html) - Pass it your content, it will return what is judges are the best keywords. It is a clever way of introspecting your content. If the keywords returned don't match what you think the content is about, then you should probably change your content.

14 October 2009 12:22 cet  

Tjarko wrote.... (site)

Hi Darren, txns, didn't know about that API. Will look into that.

14 October 2009 13:44 cet  

Mike Appenzellar wrote.... (mail)

I tried this and got "Local variable stWords on line 17 must be grouped at the top of the function body. " is this specfic to coldfusion 9?

10 December 2009 13:56 cet  

Tjarko wrote.... (site)

hi Mike,

My bad.. the following should be

<cfset list
<cfset var list

Then it will work :-)

10 December 2009 13:58 cet  

Sebastiaan wrote.... (site)

Hi Tjarko,

Would you suggest injecting meta-tags on the fly with cfhtmlhead per page using your code above? What would else be the use for this function?

25 January 2010 15:07 cet  

Tjarko wrote.... (site)

I would'nt use cfhtmlhead for anything ;-) The way we use it, is in the OnRequestEnd.cfm were we also strip all whitespace and set the title for the page. See this article http://www.mximize.com/strip-whitespace

25 January 2010 15:13 cet  

Leave your comment

Your name


Your url/website/link/email....


Some room for your reaction is placed here..



The answer to the ultimate question is?? (42 ;-))




URL en mail addresses are translated for you... life sometimes is that simple!!