CMS Made Simple: append search body to results
Ferdi Verlaan April 16 2014 12:02:24
Besides Domino work, we do a lot of other programming languages. One of them is creating websites with PHP, with CMS Made Simple. A very completed, yet easy to use, Content Management System. In this post we will explain how to display search results with the body of the page.We use the embedded 'Search' module of CMS Made Simple.
'Extensions > Search -> Result template'
We change the code to:
<h3>Search results for "{$phrase}"</h3>
{if $itemcount > 0}
{foreach from=$results item=entry}
<p><b>{$entry->title} ({$entry->weight}%)</b>
<br/>{getSearchBody url=$entry->url length=50}
<br/><a href="{$entry->url}">{$entry->urltxt}</a>
{/foreach}
</ul>
<p>{$timetaken}: {$timetook}</p>
{else}
<p><strong>{$noresultsfound}</strong></p>
{/if}
the 'getSearchBody' is a UDT, a user defined tag. We create this at 'Extensions > User Defined Tags'.
Create a new one with the name 'getSearchBody' and put the following code in:
/** Get page ID from Page URL -Create Search Body
* @params string $params['url']
* @params string $params['length']
*/
$gCms = cmsms();
$contentops =& $gCms->GetContentOperations();
$db = $gCms->GetDb();
foreach ($contentops->GetAllContent() as $page) {
if ($page->GetURL() == $params['url']) {
$cid = $contentops->GetPageIDFromAlias( $page->Alias() );
$rid = $db->GetOne('select content from '.cms_db_prefix().'content_props where content_id='.$cid.' and prop_name = "page"');
if ($rid == "") {
$string = $db->GetOne('select content from '.cms_db_prefix().'content_props where content_id='.$cid.' and prop_name = "content_en"');
} else {
$string = $db->GetOne('select content from '.cms_db_prefix().'content_props where content_id='.$rid.' and prop_name = "content_en"');
}
if($string == "<p><br /><!-- Add code here that should appear in the content block of all new pages --></p>
<p> </p>") {
$string = $db->GetOne('select content from '.cms_db_prefix().'content_props where content_id='.$cid.' and prop_name = "content_en"');
}
$string = strip_tags($string);
$words = explode(' ', $string);
if ($length ="") {
$length = 45;
}
if (count($words) > $length) {
return implode(' ', array_slice($words, 0, $length))."...";
} else {
return $string;
};
}
}
The end result is something similar like:
- Comments [2]