View Single Post
  #1  
Old 01-27-2005, 07:02 PM
 
belen belen is offline
 

Member
  
Join Date: Nov 2002
Posts: 12
 

Default Free Mod for Product Page Custom Meta Tags & Titles

Though the new versions of X-Cart are improving the ability to specify meta tags and titles for SEO, I have had many clients frustrated with not being able to optimize product pages, as these are usually where they want people to land. Below is a mod that doesn't involve modifying the database or fields - only 2 template edits and the use of an include file. I am implementing it in the 4.x branch, but I think it will translate down with no issue.

1) Create .txt files for your <head> data, including title, meta description, meta keywords and any others you wish to include. Example:
Code:
<title>Keyword 1, Keyword 2 from Company Name</title> <meta name="keywords" content="keyword phrase1,keyword phrase2,keyword phrase3,keyword phrase4,keyword phrase5"> <meta name="description" content="Keyword 1, Keyword 2 from Company Name. Descriptive sentence."> <meta name="GOOGLEBOT" content="index,follow"> <meta name="robots" content="index,follow"> <!-- This web site contains information about: keyword phrase1,keyword phrase2,keyword phrase3,keyword phrase4,keyword phrase5 -->
You will create one of these for each product, naming it with the X-Cart Product ID number (ie - "16145.txt")

2) You will upload these to a directory on your server called meta. I prefer to place mine at the root of my web directory, at the same level as my x-cart directory, so it is at "/meta/" and xcart is at "/store/"

3) First, you need to diable the default title tag if you are on a product page, since it is included in your meta include.

Open <xcart_root_dir>/skin1/customer/home.tpl and add the following code above and below the existing<TITLE> tags (existing code indicated for your reference)
Code:
***begin existing code*** <HTML> <HEAD> ***end existing code*** {if $product.product ne ""} {else} ***begin existing code*** <TITLE> x-cart title code </TITLE> ***end existing code*** {/if}

4) Now we will edit the meta template.

Open <xcart_root_dir>/skin1/meta.tpl and add the following code (existing code is marked for your reference)
Code:
***begin existing code*** <META name="ROBOTS" content="NOINDEX"> <META name="ROBOTS" content="NOFOLLOW"> {else} ***end existing code*** {if $product.product ne ""} {assign var="meta" value=$product.productid} {php} $meta = $this->get_template_vars('meta'); $meta_data = "../meta/".$meta.".txt"; readfile($meta_data); {/php} {else} ***begin existing code*** <META name="description" content="{if $current_category.meta_descr ne ""}{$current_category.meta_descr}{/if} {$config.SEO.meta_descr}"> <META name="keywords" content="{if $current_category.meta_keywords ne ""}{$current_category.meta_keywords}{/if} {$config.SEO.meta_keywords}"> {/if} ***end existing code*** {/if} ***begin existing code*** {if $webmaster_mode eq "editor"}
What we are doing is first checking to see if the product variable is set to equal anything. If it is, then we know we are on a product page. Then we assign a variable name we can use to the productID, we concatnate it with the path for the meta include file, and then ask PHP to spit out the include file for us. If we aren't on a product page, it ignores this and moves along to the standard meta data.

The fact that my clients can edit their meta data in a text file to their heart's content and I don't have to apply mods to the database and structure, thereby avoiding upgrade headaches made me very very happy. Until X-Cart realizes that product pages *are* important for some people to optimize, I am content to use this mostly un-invasive solution.

I hope this helps some of you out there - I know this is a topic that can cause much headache!

----------------------------------
belen
me@belen.net
www.belen.net
Reply With Quote