PHP
  Home arrow PHP arrow Page 3 - Using PHP to Create Relevant Title Tags in osCommerce Websites
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Using PHP to Create Relevant Title Tags in osCommerce Websites
By: Codex-M
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2009-05-21


    Table of Contents:
  • Using PHP to Create Relevant Title Tags in osCommerce Websites
  • osCommerce Web Template Files and Page Title Naming
  • Proper Page Title Naming for the Home Page and Categories
  • Proper Page Title Naming for the Product Pages

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Using PHP to Create Relevant Title Tags in osCommerce Websites - Proper Page Title Naming for the Home Page and Categories
    ( Page 3 of 4 )

    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 variable cPath in 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. The cPath ID 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 contain cPath in the URL, and by using the  preg_match function, 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 of strpos and substr 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
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek