Welcome! Log In Create A New Profile


Dynamic adaptation of <title> and <h1> tags

Posted by Tec 
Dynamic adaptation of <title> and <h1> tags
September 16, 2007 04:55PM
Sphider's title and h1 tags are fixed to 'Sphider'. It would be more comfortable to get dynamically defined tags. Nice to have for browser headlines and especially useful if a user of your search engine wants to bookmark a result page. As the names of bookmarks are extracted from the title-tag we should have a more expressive title. Here is a mod that dynamically adapts the following to the tags:

- user defined title
- category (if selected)
- search query
- page number of results

In order to enable this mod replace the whole contents of the file
with the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
$mytitle = "Sphider - a lightweight search engine." ; // Enter here your personal title for <title> and <h1> tags
if ($catid && is_numeric($catid)){
$cattree = array(" ",$sph_messages['Categories']);
$cat_info = get_category_info($catid);
foreach ($cat_info['cat_tree'] as $_val){ $thiscat = $_val['category'];
array_push($cattree," > ",$thiscat);
$cattree = implode($cattree);
<title><? if ($start < '2') $start = '1'; print $mytitle; if ($catid && is_numeric($catid)) print "$cattree" ; if ($query !='') print " Your search term: '$query'. Results from page: $start";?></title>
<link rel="stylesheet" href="<? print "$template_dir/$template/search.css";?>" type="text/css" />
<!-- suggest script -->
<style type="text/css">@import url("include/js_suggest/SuggestFramework.css"winking smiley;</style>
<script type="text/javascript" src="include/js_suggest/SuggestFramework.js"></script>
<script type="text/javascript">window.onload = initializeSuggestFramework;</script>
<!-- /suggest script -->

<h1><? print $mytitle; ?></h1>

At present the <h1> tag only holds the variable $mytitle
It might be individualized by your personal preferences.

By the way: There is a small bug in 'header.html' file. As it is hard-coded the row
<link type="text/css" rel="stylesheet" href="templates/standard/search.css">
fixes all 'search.css' stylesheets to the folder /standard/

I fixed it with the following:
<link rel="stylesheet" href="<? print "$template_dir/$template/search.css";?>" type="text/css" />

Happy coding

Sorry, only registered users may post in this forum.

Click here to login