So I'm trying to wrap my head around creating this search page. Do you have to create a search record in the CMS? I'm trying to follow this example (http://www.interactivetools.com/forum/forum-posts.php?postNum=2230147#post2230147), but it doesn't have an example for a multi-listing page.
I'm trying to search just one particular multi-listing section on the site:
list($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'perPage' => '1',
'loadUploads' => true,
'allowSearch' => true,
));
$articlesRecord = @$articlesRecords[0];
Here's the search page I'm working on. If someone could point me in the right direction that would be awesome!!
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
$libraryPath = 'cms/lib/viewer_functions.php';
$dirsToCheck = array('/home/content/85/8004985/html/themarrowmagazine/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load record from 'search'
list($searchRecords, $searchMetaData) = getRecords(array(
'tableName' => 'search',
'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$searchRecord = @$searchRecords[0]; // get first record
if (!$searchRecord) { dieWith404("Record not found!"); } // show error message if no record found
?>
<?php
// search viewer code begins
$searchOptions = array();
$searchOptions['keywords'] = @$FORM['q'];
$searchOptions['perPage'] = "3";
$searchOptions['debugSql'] = "0";
$searchTables = array();
// articles as categories
$searchTables['articles'] = array(
'viewerUrl' => 'articles.php',
'titleField' => 'title',
'summaryField' => 'content',
'searchFields' => array('title','content_column_1', 'content_column_2'),
);
list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchOptions);
// search viewer code ends
?>
<?php
/////////////////// MAX Words /////////////////////
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml, "<b></b><i></i>");
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);
return $output;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CMS Builder Search Engine</title>
<meta name="description" content="Search our website for anything related to page titles, names or page content." />
</head>
<body>
<div id="wrapper">
<div class="content-container">
<h1><?php echo htmlspecialchars($searchRecord['title']); ?></h1>
<?php echo $searchRecord['content']; ?>
<!-- search form -->
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<table width="0" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"><input name="q" type="text" class="text-field" value="<?php echo htmlspecialchars(@$FORM['q']); ?>" size="40" /></td>
<td valign="top"><input name="input" type="submit" class="form-button" value="Search" /></td>
<td valign="top"><input name="reset" type="button" class="form-button" onclick="parent.location='search.php'" value="reset" /></td>
</tr>
</table>
<h3> Search results for ( <?php echo htmlspecialchars(@$FORM['q']); ?> ) <br />
Results <b><?php echo htmlspecialchars(@$searchDetails['pageResultsStart']); ?></b> to <b><?php echo htmlspecialchars(@$searchDetails['pageResultsEnd']); ?></b> of <b><?php echo htmlspecialchars(@$searchDetails['totalRecords']); ?></b>.</h3><br />
<!-- show errors -->
<?php if ($searchDetails['invalidPageNum']): ?>
<p> Results page '<?php echo $searchDetails['page']?>' not found, <a href="<?php echo $searchDetails['firstPageLink'] ?>">start over >></a>.</p>
<!-- /show errors -->
<!-- no results -->
<?php elseif ($searchOptions['keywords'] && $searchDetails['noRecordsFound']): ?>
<h5><strong>No records matched search query!</strong></h5>
<?php elseif ($searchOptions['keywords'] == ""): ?>
<p>Type a word into the text field to begin your search.</p>
<?php endif ?>
<!-- /no results -->
<!-- display record list -->
<?php foreach ($searchRows as $record): ?>
<h3><a href="<?php echo $record['_link'] ?>"><?php echo htmlspecialchars($record['_title']); ?></a></h3>
<?php if ($record['_summary']): ?>
<p><?php echo maxWords($record['_summary'], 60); ?>...</p>
<?php else: ?>
<p>No description available.</p>
<?php endif ?>
<h4><a href="<?php echo $record['_link'] ?>">Read more</a></h4>
<hr/><br />
<?php endforeach ?>
<!-- /display record list -->
</form>
<!-- /search form -->
<!-- previous next -->
<h4><strong><?php if ($searchDetails['prevPage']): ?>
<a href="<?php echo $searchDetails['prevPageLink'] ?>">Previous</a>
<?php else: ?>
<?php endif ?>
<?php if ($searchDetails['nextPage']): ?>
<a href="<?php echo $searchDetails['nextPageLink'] ?>">Next</a>
<?php else: ?>
<?php endif ?>
<?php
if (@!$_GET['page']): $current_page = "1";
else: $current_page = $_GET['page'];
endif; ?>
<?php foreach (range(1,$searchDetails['totalPages']) as $page): ?>
<?php if ($page == $current_page): ?>
<strong><?php echo $page; ?></strong>
<?php else: ?>
<a href=""><?php echo $page; ?></a>
<?php endif ?>
<?php endforeach; ?>
</strong></h4>
<!-- /previous next -->
<!-- /end all search features -->
<!-- /content-wrapper --></div>
<!-- /wrapper --></div>
</body>
</html>