ncyoung.com

b2 Hack: when viewing a single post, post title becomes page title

This entry is in the following categories:

I had heard that Google pays particular attention to page titles when ranking pages in search results, so a couple weeks ago I modified b2 to use the post title as the page title when viewing one post at a time.

Sure enough, I'm getting a lot more google hits than before. Here's how it was done:

1. Open your blog template

2. Find the line that says:

include ("blog.header.php");

3. After that line, put the following:

if ($p){
//find title of the listing.
$sql = "SELECT * FROM $tableposts WHERE ID = $p";
//print $sql;
$tHandle = mysql_query($sql);
$tRow = mysql_fetch_assoc($tHandle);
$title = $tRow["title"];
}
else {
$title = "Default Title Here";
}


5. You can now use $title as the title in your HTMl with the following PHP tag:
<?=$title?>




Dated: 09/05/2002