Caleyjag

Posts: 868
Joined: 22 June 2007
Location: Inverness, Scotland
|
Monday, Jan 21, 2008 15:22
This converts your topic, forum & member urls from:
topic/2, forum/2, member/2
to
topic/2/title-of-topic, forum/2/forum-name, member/2/member-name
Instructions
Open up scripts/php/functions.php
Replace:
PHP CODE
<?
function bb_link($link_off, $link_on){
global $site_address, $sef_urls;
if ($sef_urls=='0'){
$link="$site_address/$link_off";
}
else{
$link="$site_address/$link_on";
}
return $link;
}
?>
With:
PHP CODE
<?
function bb_link($link_off, $link_on){
global $site_address, $sef_urls, $db_prefix;
if ($sef_urls=='1'){
$pos = strpos($link_on, "topic");
// do some sql trickery for topics...
if ($pos === false){
$pos = strpos($link_on, "forum");
if ($pos === false){
$pos = strpos($link_on, "members");
if ($pos === false){
}
else{
$explode_id = explode('/', $link_on);
$query219 = "select NAME AS TITLE from {$db_prefix}members WHERE ID='$explode_id[1]'";
$result219 = mysql_query($query219) or die("topic.php - Error in query: $query219") ;
while ($results219 = mysql_fetch_array($result219)){
$title = $results219['TITLE'];
}
// now fix the title
$title = str_replace(" ", "-", $title);
$title= strtolower($title);
$reserved = preg_quote('\/:*?"<>|!', '/');
$title = preg_replace("/([\\x00-\\x20\\x7f-\\xff{$reserved}])/e", "", $title);
$title = "/".$title;
}
}
else{
$explode_id = explode('/', $link_on);
$query219 = "select NAME AS TITLE from {$db_prefix}categories WHERE ID='$explode_id[1]'";
$result219 = mysql_query($query219) or die("topic.php - Error in query: $query219") ;
while ($results219 = mysql_fetch_array($result219)){
$title = $results219['TITLE'];
}
// now fix the title
$title = str_replace(" ", "-", $title);
$title= strtolower($title);
$reserved = preg_quote('\/:*?"<>|!', '/');
$title = preg_replace("/([\\x00-\\x20\\x7f-\\xff{$reserved}])/e", "", $title);
$title = "/".$title;
}
}
else{
$explode_id = explode('/', $link_on);
$query219 = "select TITLE from {$db_prefix}posts WHERE TITLE!='' AND TOPIC_ID='$explode_id[1]'";
$result219 = mysql_query($query219) or die("topic.php - Error in query: $query219") ;
while ($results219 = mysql_fetch_array($result219)){
$title = $results219['TITLE'];
}
// now fix the title
$title = str_replace(" ", "-", $title);
$title= strtolower($title);
$reserved = preg_quote('\/:*?"<>|!', '/');
$title = preg_replace("/([\\x00-\\x20\\x7f-\\xff{$reserved}])/e", "", $title);
$title = "/".$title;
}
}
if ($sef_urls=='0'){
$link="$site_address/$link_off";
}
else{
$link="$site_address/$link_on".$title."";
}
return $link;
}
?>
The good thing about this script is that even if the title of your topic changes, the link will still work, as it only uses the ID, not ID & title or title by itself. Same with the forum and member url's.
Remember, this is only a hack, there is a better version of this that removes the ID numbers from the url but that requires a lot more file editing. I think this method is good enough for those that want titles in url's for SEO.
Last edited by: Caleyjag
- Monday, Jan 21, 2008 15:35.
|