How to find all keyword occurencies directly from content

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Locked
osxfil
Forum Members
Forum Members
Posts: 186
Joined: Wed Apr 01, 2009 6:03 pm

How to find all keyword occurencies directly from content

Post by osxfil »

Maybe you sometimes think how to find all keyword occurencies directly from article on your website instead searching with search form. It is useful e.g. for wiki-based sites etc.
I got this idea during releasing website for Holovitalis.de (natural healing). They want to have on their website wiki-based section called Lexikon (created with CGBlog module) with FEU submit of articles. One of customer requirements was possiblity for searching all keyword occurencies accross whole website.

1. UDT
Create UDT called "keyword":

Code: Select all

$contentobj = cms_utils::get_current_content();
$page_title = '';
if (is_object($contentobj))
{
   $page_title = cms_htmlentities($contentobj->Name());
}
if ($page_title != "Neuer Artikel") { //$page_title variable change to page title where is your articles FEU submit form
$key = $params['key'];
$link = "suchen"; // page alias for search results 
echo("<a href=\"".$link."?keyword=".$key."\">".$key."</a>");
} else 
echo("{keyword key=\"Your keyword\"}");
What UDT does?
UDT convert your searched keyword to the link to page where you want display search results. Additionally provide that you can add instruction how to use the tag to the page with FEU articles submit form, for example:
If you want in your article to use searching for a keyword in the lexicon, in magazines or in the site content, use this tag: {keyword key="Your keyword"} and replace "Your keyword" with text for searching.
Searching template
Additionally update your searching template:

Code: Select all

{capture assign='term'}{$smarty.get.keyword}{/capture}
{if $term !=''}
{$startform}
<input type="text" class="search-input" id="{$search_actionid}searchinput" name="{$search_actionid}searchinput" size="20" maxlength="50" value="{$term}"/>
{if isset($hidden)}{$hidden}{/if}
{$endform}
{literal}
<__script__ type="text/javascript">
  window.onload=function(){
    document.forms["cntnt01moduleform_1"].submit();
  }
</__script>
{/literal}

{else}
{$startform}
<input type="text" class="search-input" id="{$search_actionid}searchinput" name="{$search_actionid}searchinput" size="20" maxlength="50" value="{$searchtext}" {$hogan}/>
{if isset($hidden)}{$hidden}{/if}
{$endform}
{/if}
(please delete __ before and after "script")
Search form providing auto-submit in case URL parameter "term" is exists. If is URL param "term" empty or if not exists, standard search from will displayed.

How to use
Using of this feature is very simple. Each allowed backend users (admins, editors…) and FEU users (if you have allowed submiting articles by FEU) can use this tag directly on their text:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vel arcu mollis arcu lacinia pulvinar consequat nec libero. {keyword key="Curabitur"} ullamcorper ullamcorper libero sit amet vestibulum. Mauris nulla enim, consequat aliquam rhoncus ut, rutrum vulputate justo. Donec tellus justo, mattis quis laoreet eget, malesuada ut augue. Nam aliquam malesuada sagittis. Morbi ante quam, feugiat sit amet euismod ac, tristique non dui. Quisque at sem leo. In hac habitasse platea dictumst. Donec imperdiet nulla id nulla imperdiet iaculis. Morbi nec erat est, vitae laoreet dui. Morbi lobortis augue eu magna luctus vitae molestie lectus eleifend. Ut est nisl, tincidunt eu tempor in, eleifend<a href="{cms_selflink href='a'}">volutpat</a> augue. Nam aliquet auctor felis ac feugiat. Quisque aliquet purus a felis malesuada fringilla.</p>

Live example: go to http://develop.bocekmedia.net/2013/09/Ferrum-metallicum and click to "Curabitur" keyword
chandra

Re: How to find all keyword occurencies directly from conten

Post by chandra »

Thx for sharing this - very helpful.

By the way - with Smarty 3 you can make things like this
osxfil wrote:

Code: Select all

{capture assign='term'}{$smarty.get.keyword}{/capture}
a lot shorter ;)

Code: Select all

{$term = $smarty.get.keyword}
osxfil
Forum Members
Forum Members
Posts: 186
Joined: Wed Apr 01, 2009 6:03 pm

Re: How to find all keyword occurencies directly from conten

Post by osxfil »

Yeah, sure. Force of habit ;)
Locked

Return to “Tips and Tricks”