BabbleBoard Support Forums
What Are YOU Babbling About?
Hello Guest!  |  Home  |  Search  |  Login  |  Register
Home | [1.1.5] Completed Modifications | [1.1.5] - Title in URL hack
[1.1.5] - Title in URL hack
Caleyjag



Role

Posts: 868
Joined: 22 June 2007
Location: Inverness, Scotland
Monday, Jan 21, 2008 15:22  Trackback URL

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); 
                
$titlestrtolower($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); 
                
$titlestrtolower($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); 
                
$titlestrtolower($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.
Go To Top
PutzMan123



Role

Posts: 396
Joined: 22 June 2007
Location: London, England
BabbleBoard Version: v1.1.5

Monday, Jan 21, 2008 16:15  Trackback URL

I like that a lot Great idea actually

Go To Top
 
1 Guest(s), 0 Member(s) Viewing This Topic:
 
 
 
Powered by BabbleBoard v1.1.6
All Content © BabbleBoard Support Forums