Javascript code for the submission form
Code: Select all
function CheckForm() {
with(self.document.searchform) {
if (catselect.selectedIndex==0)
{
cntnt01modules.value = "";
}
submit();
}
}
Search template. The categories are the same as those set up as categories in the CGBlog. If you wanted these automated you could using the Browsecat template to populate the categories in the select box.
Code: Select all
{$startform|replace:'<form':'<form onsubmit="return CheckForm(this);" name="searchform"'}
<select id="catselect" onchange="form.{$search_actionid}passthru_CGBlog_category.value=this.options[this.selectedIndex].value">
<option value="">Search Site</option>
<option value="Association News">Association News</option>
<option value="Comment">Comment</option>
<option value="Education">Education</option>
<option value="In And Out">In & Out</option>
<option value="Industry Profiles">Industry Profiles</option>
<option value="Latest News">Latest News</option>
<option value="Results">Results</option>
<option value="Roundtables">Roundtables</option>
</select>
<input type="text" class="text-input" id="{$search_actionid}searchinput" name="{$search_actionid}searchinput" size="20" maxlength="50" value="{$searchtext}" {$hogan} /><span class="searchbutt"><input type="image" name="myclicker" src="/uploads/images/site/butt-search-lilac.gif" /></span><br />
{if isset($hidden)}{$hidden}{/if}
{$endform}
Search Results template
Code: Select all
{if $smarty.post.cntnt01passthru_CGBlog_category}
<h3>Search results for "{$phrase}" in {$smarty.post.cntnt01passthru_CGBlog_category}</h3>
{else}
<h3>Search results for "{$phrase}"</h3>
{/if}
{if $itemcount > 0}
<ol style="margin-left:18px;">
{counter start="0" assign="mycounter"}
{foreach from=$results item=entry}
{if $smarty.post.cntnt01passthru_CGBlog_category}
{if $entry->title == "Calguys Blog Module"}
{counter assign="mycounter"}
<li><a href="{$entry->url}">{$entry->urltxt}</a></li>
{/if}
{else}
<li><a href="{$entry->url}">{$entry->urltxt}</a></li>
{/if}
{/foreach}
</ol>
{if $smarty.post.cntnt01passthru_CGBlog_category && $mycounter == 0}
<p><strong>{$noresultsfound}</strong></p>
{/if}
{else}
<p><strong>{$noresultsfound}</strong></p>
{/if}
Code to add to CGBlog.module.php insert above function SearchResult
Code: Select all
// CODE FOR CATEGORY SEARCH
function SearchResultWithParams($returnid,$articleid,$attr='',$params=array())
{
$result = array();
if ($attr == 'cgblog')
{
$db =& $this->GetDb();
$now = $db->DbTimeStamp(time());
$zerotime = $db->DbTimeStamp(1);
$q = "SELECT cgblog_title FROM ".cms_db_prefix()."module_cgblog cgb ";
$where = " WHERE cgblog_id = ? ";
if(!empty($params['category']))
{
$where .= " AND c.name = '".$params['category']."' ";
$q .= " LEFT JOIN ".cms_db_prefix()."module_cgblog_blog_categories bc ON (bc.blog_id = cgb.cgblog_id)";
$q .= " LEFT JOIN ".cms_db_prefix()."module_cgblog_categories c ON (bc.category_id = c.id )";
}
if( $this->GetPreference('expired_searchable',1) == 0 )
{
// make sure we don't return expired articles.
// if we don't want em to.
$where .= " AND ((".$db->IfNull('end_time',$zerotime)." = ".$zerotime.") OR (end_time > $now))";
}
$dbresult = $db->Execute( $q.$where, array( $articleid ) );
//echo $db->sql;
while($dbresult && $row=$dbresult->FetchRow())
{
//0 position is the prefix displayed in the list results.
$result[0] = $this->GetFriendlyName();
//1 position is the title
$result[1] = $row['cgblog_title'];
//2 position is the URL to the title.
$aliased_title = munge_string_to_url($row['cgblog_title']);
$prettyurl = $this->GetPreference('urlprefix','cgblog').'/' . $articleid.'/'.$returnid."/$aliased_title";
$result[2] = $this->CreateLink('cntnt01', 'detail', $returnid, '', array('articleid' => $articleid) ,'', true, false, '', true, $prettyurl);
}
}
return $result;
}
Code: Select all
{search resultpage='search-results' passthru_CGBlog_category='' search_method='post' searchtext=''}
Enjoy...