Home arrow PHP arrow Page 3 - Using PHP to Create Relevant Title Tags in osCommerce Websites

Proper Page Title Naming for the Home Page and Categories - PHP

If you use osCommerce for your site's e-commerce, and you're not happy with the quality or quantity of visitors your site receives, keep reading. Though osCommerce provides some excellent features, its weaknesses could be getting in the way of giving you the number of visitors and conversions you expect. Fortunately, there's a solution, hidden in something as simple as a title tag.

TABLE OF CONTENTS:
  1. Using PHP to Create Relevant Title Tags in osCommerce Websites
  2. osCommerce Web Template Files and Page Title Naming
  3. Proper Page Title Naming for the Home Page and Categories
  4. Proper Page Title Naming for the Product Pages
By: Codex-M
Rating: starstarstarstarstar / 8
May 21, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

General warning:Before doing any on-site work, do not forget to back up your original files.

Now that we know the basic files that need to be edited to give your site the most relevant and unique page titles, we will come up with a good strategy to change those titles into something we want.

  1. The home page Title should be an SEO-optimized title tag. 

  2. We can use the category variablecPathin the URL to fetch the correct category name in the MySQL database. As long as the URL is given, we can use PHP to analyze the URL, grab the category ID number, communicate to the MySQL database and finally grab the corresponding category name.
  3. The appropriate product category name should then be returned as the category page title.

  4. The same technique will be applied to the product pages. ThecPathID number corresponds to the product ID with the corresponding product name in the MySQL database.

 

PHP script for producing unique titles for the home page and category pages (actual script in blue):

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<?php

$optimizedurl=$_SERVER["REQUEST_URI"];

if (preg_match("/cPath/i", $optimizedurl))

{

//this is a category page, extract the category name

$location1=(strpos($optimizedurl,'cPath'));

$start= $location1 + 6;

$categoryextracted=substr($optimizedurl,$start,2);

$result = mysql_query("SELECT `categories_name` FROM `categories_description` WHERE `categories_id`='$categoryextracted'")

or die(mysql_error());

$row = mysql_fetch_array($result)

or die("Invalid query: " . mysql_error());

echo "<br />";

$titletag = $row['categories_name'];

}

else

//this is the root page

{

$titletag = 'Put your SEO optimized title tag here for the homepage';

}

?>

<title><?php echo $titletag ?></title>

Let me explain how the PHP script above will get the appropriate page title. It starts with

$optimizedurl=$_SERVER["REQUEST_URI"];

This script will get the URL of the page and store it to a variable. Note that$_SERVER["REQUEST_URI"]is not perfectly compatible with Windows Server, and there are things that need to be adjusted; explaining them is beyond the scope of this tutorial. However, you can read it here:

http://www.php.net/reserved.variables

Now, since the index.php will cover both the home page and the category pages, we need to determine whether the URL analyzed by PHP is for a category page or the root URL. This script will provide the answer:

if (preg_match("/cPath/i", $optimizedurl))

{

Category pages containcPath in the URL, and by using the preg_matchfunction, we can test to see if it contains this variable.

If it is a category page, the next job of the script is getting the category ID, which will be used to pull out the category name in the MySQL database:

//this is a category page, extract the category name

$location1=(strpos($optimizedurl,'cPath'));

$start= $location1 + 6;

$categoryextracted=substr($optimizedurl,$start,2);

$result = mysql_query("SELECT `categories_name` FROM `categories_description` WHERE `categories_id`='$categoryextracted'")

or die(mysql_error());

$row = mysql_fetch_array($result)

or die("Invalid query: " . mysql_error());

echo "<br />";

$titletag = $row['categories_name'];

The combination ofstrposandsubstr will extract the category ID from the URL.

For example:

http://localhost/osc/index.php?cPath=4&osCsid=2a003844f541432aa794b92c2ece050d

The category ID in the above URL is the value of the cPath variable, which is 4.

The rest of the above script's purpose will be to query the database in order to extract the category name.



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: