Kennisbank > cms made simple, php > CMS Made Simple: append search body to results

CMS Made Simple: append search body to results

Ferdi Verlaan

Ferdi Verlaan

Manager OTC & NOC

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 &quot;{$phrase}&quot;</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:

 

Ferdi Verlaan

Over de auteur

Ferdi Verlaan

Werkzaam bij AASHQ sinds 2005, beheert en inspireert Ferdi een team van uitstekende ontwikkelaars, systeem- en netwerkingenieurs.

Hij is bedreven in verschillende programmeertalen maar ook zeer kundig in zowel Windows (Server) als Linux-besturingssystemen.

Ook interessante artikelen

Deze artikelen kunnen jou ook misschien aanspreken

woensdag 26 april 2023

De snelheid van onze nieuwe website

Ferdi Verlaan

Ferdi Verlaan

Manager OTC & NOC

Ferdi Verlaan

Ferdi Verlaan

Manager OTC & NOC

Neem contact met ons op

En breng jouw IT omgeving ook naar 'the next level'.

Neem contact op