Basically I've got an old static html site ( http://www.brownwatson.co.uk/brochure/page1.html ) I need to add a search box to it to search a folder called /brochure within that folder is html documents and images etc I need the search to find ISBN numbers, Book Reference Numbers, Titles etc.. There's no database the hosting provider has got php I was trying to create something like this:
<div id="contentsearch">
<form id="searchForm" name="searchForm" method="post" action="search.php">
<input name="search" type="text" value="search" maxlength="200" />
<input name="submit" type="submit" value="Search" />
</form>
<?php
$dir = "/brochure/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($file == $_POST['search']){
echo('<a href="'.$dir . $file.'">'. $file .'</a>'."\n");
}
}
closedir($dh);
}
}
?>
</div>
I know, I know this is pretty bad and doesn't work any ideas? I haven't created anything like this in years, and have pretty much just taken bits of code and stuck it together!
So how to include search on a static website? In short, you have to generate an index from selected content of the pages of your site, create a search and API to have access to the index, and create a user interface so your users can search the index and see search results on the web page.
Both static and dynamic websites can serve you well for SEO purposes or damage your rankings. Static websites are great for SEO because they have cool loading speeds, their HTML code is more understandable for SEs to index, they are more secure and more stable to a great wave of visitors.
A static website consists of a set of HTML, CSS, and JavaScript files that serve website content. Simple static websites have no dynamic functionality, and are best used for personal or marketing sites.
There are quite a few solutions available for this. In no particular order:
Free or Open Source
See also http://indieweb.org/search#Software
Subscription (aka paid) Services:
A very, very lazy option (to avoid setting up a Google Custom Search Engine) is to make a form that points at Google with a hidden query element that limits the search to your own site:
<div id="contentsearch">
<form id="searchForm" name="searchForm" action="http://google.com/search">
<input name="q" type="text" value="search" maxlength="200" />
<input name="q" type="hidden" value="site:mysite.com"/>
<input name="submit" type="submit" value="Search" />
</form>
</div>
Aside from the laziness, this method gives you a bit more control over the appearance of the search form, compared to a CSE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With