I added the 2 new functions to inlcude/functions.php pretty mutch just as Fattymatty posted them, here they are again for convenience ... I just pasted them under the comments at the top of functions.php
| Code: |
///SEO goods - ADDED FOR TITLE AND KEYWORDS CUSTOMIZATION
///submitted by users of the pre-2008 dew-code.com forum
function get_cat($PID){
global $tb_categories;
$gc_query = sql_query(" select $tb_categories.Category as cat_name from $tb_categories where ID=$PID");
while($gc_array = sql_fetch_array($gc_query)){
$cat = $gc_array[cat_name];
}
return $cat;
}
function get_ParentCats($PID){
global $tb_categories;
$gcid = $PID;
while($gcid > 0){
$query_str = "select $tb_categories.Category,
$tb_categories.ID,
$tb_categories.PID from $tb_categories where $tb_categories.ID = $gcid";
$mlc_query = sql_query($query_str);
$mlc_array = sql_fetch_array($mlc_query);
$cat_array[] = $mlc_array["Category"];
$pid_array[] = $mlc_array["ID"];
$gcid = $mlc_array["PID"];
}
$count = sizeof($pid_array);
for($depth=$count;$depth>=0;$depth--){
if($pid_array[$depth]){
if($PID == $pid_array[$depth]){
$htmlsrc .= ereg_replace("_"," ",($cat_array[$depth]));
$htmlsrc .= "";
} else {
$htmlsrc .= ereg_replace("_"," ",($cat_array[$depth]));
$htmlsrc .= ", ";
}
}
}
return $htmlsrc;
}
//END ADDED FOR TITLE AND KEYWORD CUSTOMIZATION
|
Then editing the directory file, I did things abit differently. Basically the get_ParentCats function could be very CPU intensive on a deeply nested category, so I wanted to be sure I only call the function once per page view. With the output assigned to a variable, I can just print the variable when and where I want it.
Around line #76, under
I added the function calls to fetch the entire category trail only if the $PID was greater than 3, since the install I'm working on only has 3 top level categories... Change the "3" to the number of top level categories you have, this just ensures you dont call the more expensive get_ParentCats function unneccesarily.
| Code: |
if ($PID > 3){
$keywords = get_ParentCats($PID);
} else {
$keywords = get_cat($PID);
}
|
Then I just print the $keyword variable within in the keyword, description and title tags
| Code: |
<meta name = "keywords" content = " blah blah blah <?php echo $keywords;?>
<meta name = "description" content = "<?php echo $gl[SiteTitle] .'blah'.$keywords; ?>
. . . . . . . . .
<title>
<? echo "$gl[SiteTitle]";
echo ' '. $keywords;
?>
|
Now I just need to write a great site all about blah !