Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Dynamic Meta Tags


bad_lemming

Recommended Posts

in product_info.php

 

I replaced:

 

<title><?php echo TITLE; ?></title>

 

with

// Dynamic Meta Tags Start
if (isset($products_id)) {
    $product_info = tep_db_query("select p.products_id, pd.products_name, pd.products_description from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and pd.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and pd.language_id = '" . $languages_id . "'");
    $product_info_values = tep_db_fetch_array($product_info);
    $meta_keywords = strip_tags($product_info_values['products_description']);
    $meta_keywords = substr($meta_keywords, 0, 250);
    echo '<title>' . $product_info_values['products_name'] . ' ' . TITLE . '</title>';
    echo '<meta name="description" content="' . $meta_keywords . '">';
    echo '<meta name="keywords" content="' . str_replace(" ", ", ", $product_info_values['products_name']) . '">';
}
// Dynamic Meta Tags End
else {
    echo '<title>' . TITLE . '</title>';
}

 

any ideas why this no workey?

Link to comment
Share on other sites

I assume you are using MS2 with my dynamic meta tags contribution?

 

Here is an update for this which I have not posted yet, but shall shortly as a full package. Do this in product_info.php:

 

FIND THIS:

$product_check_query = tep_db_query('select count(*) as total from ' . TABLE_PRODUCTS . ' p, ' . TABLE_PRODUCTS_DESCRIPTION . ' pd where p.products_status = '1' and p.products_id = ' . (int)$HTTP_GET_VARS['products_id'] . ' and pd.products_id = p.products_id and pd.language_id = ' . (int)$languages_id);
 $product_check = tep_db_fetch_array($product_check_query);

 

DIRECLTY AFTER ADD THIS:

 

//begin dynamic meta tags query -->
 $the_product_info_query = tep_db_query('select pd.language_id, p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from ' . TABLE_PRODUCTS . ' p, ' . TABLE_PRODUCTS_DESCRIPTION . ' pd where p.products_id = ' . (int)$HTTP_GET_VARS['products_id'] . ' and pd.products_id = ' . (int)$HTTP_GET_VARS['products_id'] . '' . ' and pd.language_id =' . (int)$languages_id);
 $the_product_info = tep_db_fetch_array($the_product_info_query);
 $the_product_name = strip_tags ($the_product_info['products_name'], "");
 $the_product_model = strip_tags ($the_product_info['products_model'], "");
 $the_product_description = preg_replace(array('/[\r\n]/', '/ /'), '  ', strip_tags($the_product_info['products_description'], ""));
 $the_product_description = preg_replace('/ +/', ' ', $the_product_description);
 if (strlen($the_product_description) > 250) {
   $sub_description = wordwrap($the_product_description, 250, '$@$');
   $sub_des = explode('$@$', $sub_description);
   $the_product_description = $sub_des[0];
 }

 $the_manufacturer_query = tep_db_query('select m.manufacturers_id, m.manufacturers_name from ' . TABLE_MANUFACTURERS . ' m left join ' . TABLE_MANUFACTURERS_INFO . ' mi on (m.manufacturers_id = mi.manufacturers_id and mi.languages_id = ' . (int)$languages_id . '), ' . TABLE_PRODUCTS . ' p  where p.products_id = ' . (int)$HTTP_GET_VARS['products_id'] . ' and p.manufacturers_id = m.manufacturers_id');
 $the_manufacturers = tep_db_fetch_array($the_manufacturer_query);
// end dynamic meta tags query -->

 

FIND THIS:

 

<title><?php echo TITLE ?></title>

 

AND REPLACE WITH THIS:

 

<?php
//begin dynamic meta tags query -->
?>
<title><?php echo (($the_product_name != '') ? $the_product_name : TITLE); ?></title>
<meta name="keywords" content="<?php echo $the_product_name, $the_product_model, $the_manufacturers['manufacturers_name']; ?>, your, additional, keywords, here">
<meta name="description" content="<?php echo $the_product_name . ': ' . $the_product_description; ?>">
<?php
//end dynamic meta tags query -->
?>

 

In the above code snippet be sure to replace the area that reads as:

 

your, additional, keywords, here

 

With whatever additional keywords you wish to use on your product pages. Otherwise you can short it to this:

 

<?php
//begin dynamic meta tags query -->
?>
<title><?php echo (($the_product_name != '') ? $the_product_name : TITLE); ?></title>
<meta name="keywords" content="<?php echo $the_product_name, $the_product_model, $the_manufacturers['manufacturers_name']; ?>">
<meta name="description" content="<?php echo $the_product_name . ': ' . $the_product_description; ?>">
<?php
//end dynamic meta tags query -->
?>

 

You will notice that in this revision, the store name has been removed from the page title when you view the page, and only reads as the product title. This was done intentionally to rank better on search engines.

 

This should work well for your needs. Let me know if you run into any issues. I worked on creating this piece with one of my developers awhile ago and have been tweaking it since.

Sincerely,

Bruce

 

19 contributions submitted

Link to comment
Share on other sites

You sir, are nifty. This is great, all looks to be well, but I will be testing further for a day or two, if I have any issues I will let you know.

Thanks again.

 

Keep me posted. Works wonderfully for our customers various sites.

Sincerely,

Bruce

 

19 contributions submitted

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...