X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Page Title in 4.2 (https://forum.x-cart.com/showthread.php?t=46663)

cflsystems 03-31-2009 11:53 AM

Page Title in 4.2
 
4.2 came out with some new features including meta keywords, meta descriptions and clean url's, but QT left out something very important - PAGE TITLE. Page title is still "product name-category name-store name" or "store name-category name-product name" and there is no setting to change that. I wonder why they didn't include page title for products, categories, static pages....
Anyway here is how this can be added. Please note that this is for stores that do not have 3rd party SEO addons and is for 4.2. Please make backups to your DB and store files first

1. Add new field to xcart_products table. I called my
product_page_title and is varchar(255), latin1_swedish_ci

2. Add new language variable - lbl_product_page_title with value "Product Page Title"

3. Open include/product_modify.php and find
Code:

$query_data = array(
and add to the array
Code:

"product_page_title" => $product_page_title

4. Open skin1/main/product_details.tpl and add
Code:

<tr>
 {if $geid ne ''}<td width="15" class="TableSubHead"><input type="checkbox" value="Y" name="fields[product_page_title]" /></td>{/if}
 <td class="FormButton" nowrap="nowrap">{$lng.lbl_product_page_title}:</td>
 <td class="ProductDetails"><input type="text" name="product_page_title" class="InputWidth" value="{$product.product_page_title|escape:"html"}" /></td>
</tr>

when you want it to appear when adding/modifying product in admin. I would add it after [keywords]

5. Open include/import_products.php and find
Code:

$import_specification["PRODUCTS"] = array(
and add to the array
Code:

"product_page_title"=> array()

6. Open skin1/customer/service_head.tpl and find
Code:

{$html_page_title|escape}
and replace with
Code:

{if $product.product_page_title ne ""}
 {$product.product_page_title}
{else}
 {$html_page_title|escape}
{/if}


Same logic can be applied to the categories changing the coresponding files

alec.thomas 04-05-2009 10:17 AM

Re: Page Title in 4.2
 
this is very usefull, thank you for this post. I've been thinking about something like this for a while. It always looks good in serp's when your title does not get cut off half way on a word. I've changed it up a little though.

This line of code for skin1/main/product_details.tpl , i've added a maxchar limit to where google truncates the title tag:



Code:

<tr>


{if $geid ne ''}<td width="15" class="TableSubHead"><input type="checkbox" value="Y" name="fields[product_page_title]" /></td>{/if}
<td class="FormButton" nowrap="nowrap">{$lng.lbl_product_page_title}:</td>
<td class="ProductDetails"><input type="text" name="product_page_title" maxlength="64" class="InputWidth" value="{$product.product_page_title|escape:"html"}" /></td>
</tr>





or what would be even better than this is a char counter on the text box that would show you how many characters you have left before Google truncation, but still allowed you to make a longer title tag.



cflsystems 04-05-2009 01:50 PM

Re: Page Title in 4.2
 
Yes Google picks up the first 64 characters but you can still show more in the title. That's the reason i left it without 64 character restriction. Glad someone got use of it though :)

presson83 04-29-2009 11:28 AM

Re: Page Title in 4.2
 
FANTASTIC mod clf! Thanks a TON for this.

Would you happen to know how to do this same thing for static pages / mind giving a quick tutorial on how to do it?

Thanks again!

cflsystems 04-29-2009 12:02 PM

Re: Page Title in 4.2
 
Happy it works out for you. I haven't done it for anything except product and category pages. The default x-cart way for right now works fine for my static pages so I didn't even look at the code and try to change it. I would say if you follow the same logic you will find the way. I might look at doing this a later time

cflsystems 05-01-2009 05:50 AM

Re: Page Title in 4.2
 
OK guys here it is. This mod is for stores that do not use any 3rd party SEO mods and was tested on 4.2.1. I am pretty sure it will work on 4.2 as well. Use it and/or modify it in any way you want to fit your needs, after all it is FREE, just please do not charge other people for it claiming is something you did :)

1. Backup your store and database first. Better yet try this mod on a test store and make sure it works before applying it to your live store.

2. Adding language variables. You can use myphpadmin or x-cart patch/upgrade section for this, or just add them manually in the language section
Code:


INSERT INTO `xcart_languages` (`code`, `name`, `value`, `topic`) VALUES ('US', 'lbl_category_page_title', 'Category Page Title', 'Labels');
INSERT INTO `xcart_languages` (`code`, `name`, `value`, `topic`) VALUES ('US', 'lbl_product_page_title', 'Product Page Title', 'Labels');
INSERT INTO `xcart_languages` (`code`, `name`, `value`, `topic`) VALUES ('US', 'lbl_manufacturer_page_title', 'Manufacturer Page Title', 'Labels');
INSERT INTO `xcart_languages` (`code`, `name`, `value`, `topic`) VALUES ('US', 'lbl_pages_page_title', 'Static Page Title', 'Labels');
INSERT INTO `xcart_languages` (`code`, `name`, `value`, `topic`) VALUES ('US', 'lbl_page_title_what_is', 'What is Page Title?', 'Labels');
INSERT INTO `xcart_languages` (`code`, `name`, `value`, `topic`) VALUES ('US', 'txt_page_title_descr', 'Every html document (page) must have a TITLE element in its head section. This title element should be used to identify the contents of the document and is one of the most important factors for SEO friendly web page. The title should be less then 64 characters in length and it should contain your primary keyword phrase for that page and any secondary keyword phrase that you may be targeting.', 'Text');


3. Adding new fields for category, product, manufacturer and static pages in the corresponding tables. You can use myphpadmin or x-cart patch/upgrade section for this.
Code:

ALTER TABLE `xcart_categories` ADD `category_page_title` varchar(255) Not Null
ALTER TABLE `xcart_products` ADD `product_page_title` varchar(255) Not Null
ALTER TABLE `xcart_manufacturers` ADD `manufacturer_page_title` varchar(255) Not Null
ALTER TABLE `xcart_pages` ADD `pages_page_title` varchar(255) Not Null


4. FOR CATEGORY PAGE TITLE
open admin/category_modify.php, find
Code:


$data = array(
"category" => $category_name,
"description" => $description,
"meta_description" => $meta_description,
"meta_keywords" => $meta_keywords,
"avail" => $avail,
"order_by" => $order_by,
"override_child_meta" => $override_child_meta
);

and replace with
Code:


$data = array(
"category" => $category_name,
"description" => $description,
"meta_description" => $meta_description,
"meta_keywords" => $meta_keywords,
"avail" => $avail,
"order_by" => $order_by,
"override_child_meta" => $override_child_meta,
"category_page_title" => $category_page_title #Added by CFL Systems for category page title
);


open skin1/admin/main/category_modufy.tpl, find
Code:

<tr>
<td height="10" class="FormButton" nowrap="nowrap">{$lng.lbl_category}:</td>
<td width="10" height="10"><font class="Star">*</font></td>
<td height="10">
<input type="text" name="category_name" id="category_name" maxlength="255" size="65" value="{if $category_error ne ""}{$smarty.post.category_name|escape:"html"}{elseif $mode ne "add"}{$current_category.category|escape:"html"}{/if}" {if $config.SEO.clean_urls_enabled eq "Y"}onchange="javascript: if (this.form.clean_url.value == '') copy_clean_url(this, this.form.clean_url)"{/if}/>
{if $category_error ne ""}
{if $category_error eq "2"}
<font color="red">&lt;&lt; {$lng.lbl_category_already_exists}</font>
{else}
<font color="red">&lt;&lt; {$lng.lbl_category_wrong_value}</font>
{/if}
{/if}
</td>
</tr>

and after it insert
Code:


{* Added by CFL Systems for category page title *}
<tr>
<td height="10" class="FormButton" nowrap="nowrap">{$lng.lbl_category_page_title}:</td>
<td width="10" height="10">&nbsp;</td>
<td height="10">
<input type="text" name="category_page_title" id="category_page_title" maxlength="64" size="100" value="{if $category_error ne ""}{$smarty.post.category_page_title|escape:"html"}{elseif $mode ne "add"}{$current_category.category_page_title|escape:"html"}{/if}" />
<a href="javascript:void(0);" class="NeedHelpLink" onmouseover="javascript: viewHelp('help_what_is_page_title', this);">{$lng.lbl_page_title_what_is}</a>
<div id="help_what_is_page_title" class="NeedHelpBox" style="display:none">{$lng.txt_page_title_descr}</div>
</td>
</tr>
{* Added by CFL Systems for category page title *}


open include/import_categories.php, find
Code:

define('IMPORT_CATEGORIES', 1);
$import_specification["CATEGORIES"] = array(

and add to the array
Code:

"category_page_title" => array() #Added by CFL Systems for category page title

in the same include/import_categories.php find
Code:


if (isset($category['product_count']))
$data['product_count'] = $category['product_count'];

and after it insert
Code:


if (isset($category['category_page_title']))
$data['category_page_title'] = $category['category_page_title']; #Added by CFL Systems for category page title


5. FOR PRODUCT PAGE TITLE
open include/product_modify.php and find
Code:


$query_data = array(
"product" => $product,
"keywords" => $keywords,

and add to the array
Code:


"product_page_title" => $product_page_title #Added by CFL Systems for product page title


open skin1/main/product_details.tpl, find
Code:


<tr>
{if $geid ne ''}<td width="15" class="TableSubHead"><input type="checkbox" value="Y" name="fields[product]" /></td>{/if}
<td class="FormButton" nowrap="nowrap">{$lng.lbl_product_name}* :</td>
<td class="ProductDetails">
<input type="text" name="product" id="product" size="45" class="InputWidth" value="{$product.product|escape}" {if $config.SEO.clean_urls_enabled eq "Y"}onchange="javascript: if (this.form.clean_url.value == '') copy_clean_url(this, this.form.clean_url)"{/if} />
{if $top_message.fillerror ne "" and $product.product eq ""}<font class="Star">&lt;&lt;</font>{/if}
</td>
</tr>

and after it insert
Code:


{* Added by CFL Systems for product page title *}
<tr>
{if $geid ne ''}<td width="15" class="TableSubHead"><input type="checkbox" value="Y" name="fields[product_page_title]" disabled="disabled" /></td>{/if}
<td class="FormButton" nowrap="nowrap">{$lng.lbl_product_page_title}:</td>
<td class="ProductDetails"><input type="text" name="product_page_title" maxlength="64" size="100" class="InputWidth" value="{$product.product_page_title|escape:"html"}" />
<a href="javascript:void(0);" class="NeedHelpLink" onmouseover="javascript: viewHelp('help_what_is_page_title', this);">{$lng.lbl_page_title_what_is}</a>
<div id="help_what_is_page_title" class="NeedHelpBox" style="display:none">{$lng.txt_page_title_descr}</div></td>
</tr>
{* Added by CFL Systems for product page title *}


open include/import_products.php and find
Code:


$import_specification["PRODUCTS"] = array(

and add to the array
Code:


"product_page_title" => array() # ADDED by CFL Systems for product page title


Continue in the next thread

cflsystems 05-01-2009 06:00 AM

Re: Page Title in 4.2
 
...... from the previous thread

6. FOR MANUFACTURER PAGE TITLE
open modules/Manufacturers/manufacturers.php and find
Code:


$query_data = array(
"url" => $url,
"descr" => $descr,
"meta_keywords" => $meta_keywords,
"meta_description" => $meta_description
);

and replace with
Code:


$query_data = array(
"url" => $url,
"descr" => $descr,
"meta_keywords" => $meta_keywords,
"meta_description" => $meta_description,
"manufacturer_page_title" => $manufacturer_page_title #Added by CFL Systems for manufacturer page title
);

in the same file find
Code:


$query_data = array(
"manufacturer" => $manufacturer,
"provider" => $login,
"descr" => $descr,
"url" => $url,
"meta_keywords" => $meta_keywords,
"meta_description" => $meta_description
);

and replace with
Code:


$query_data = array(
"manufacturer" => $manufacturer,
"provider" => $login,
"descr" => $descr,
"url" => $url,
"meta_keywords" => $meta_keywords,
"meta_description" => $meta_description,
"manufacturer_page_title" => manufacturer_page_title # Added by CFL Systems for manufacturer page title
);


open skin1/modules/Manufacturers/manufacturers.tpl, find
Code:


<tr>
<td width="20%" class="FormButton">{$lng.lbl_manufacturer}:</td>
<td><font class="Star">*</font></td>
<td width="80%"><input type="text" name="manufacturer" id="manufacturer" size="50" value="{$manufacturer.manufacturer|escape}" style="width:80%"{$disabled} {if $config.SEO.clean_urls_enabled eq "Y" && $administrate}onchange="javascript: if (this.form.clean_url.value == '') copy_clean_url(this, this.form.clean_url)"{/if} /></td>
</tr>

and after it insert
Code:


{* Added by CFL Systems for manufacturer page title *}
<tr>
<td width="20%" class="FormButton">{$lng.lbl_manufacturer_page_title}:</td>
<td>&nbsp;</td>
<td width="80%"><input type="text" name="manufacturer_page_title" id="manufacturer_page_title" maxlength="64" size="100" value="{$manufacturer.manufacturer_page_title|escape}" style="width:80%"{$disabled} />
<a href="javascript:void(0);" class="NeedHelpLink" onmouseover="javascript: viewHelp('help_what_is_page_title', this);">{$lng.lbl_page_title_what_is}</a>
<div id="help_what_is_page_title" class="NeedHelpBox" style="display:none">{$lng.txt_page_title_descr}</div></td>
</tr>
{* Added by CFL Systems for manufacturer page title *}


7. FOR STATIC PAGE TITLE
open admin/pages.php, find
Code:


$page_modified = array(
"pagetitle" => $pagetitle,
"pagecontent" => $pagecontent,
"meta_keywords" => $meta_keywords,
"meta_description" => $meta_description,
"clean_url" => $clean_url
);

and replace with
Code:


$page_modified = array(
"pagetitle" => $pagetitle,
"pagecontent" => $pagecontent,
"meta_keywords" => $meta_keywords,
"meta_description" => $meta_description,
"clean_url" => $clean_url,
"pages_page_title" => $pages_page_title # Added by CFL Systems for static page title
);

in the same file find
Code:


$query_data = array(
'filename' => $filename,
'title' => $pagetitle,
'level' => $level,
'orderby' => intval($orderby),
'active' => $active,
'language' => $current_language,
"show_in_menu" => $show_in_menu,
"meta_keywords" => $meta_keywords,
"meta_description" => $meta_description
);

and replace with
Code:


$query_data = array(
'filename' => $filename,
'title' => $pagetitle,
'level' => $level,
'orderby' => intval($orderby),
'active' => $active,
'language' => $current_language,
"show_in_menu" => $show_in_menu,
"meta_keywords" => $meta_keywords,
"meta_description" => $meta_description,
"pages_page_title" => $pages_page_title # Added by CFL Systems for static page title
);

in the same file find
Code:


$query_data = array(
'title' => $pagetitle,
'orderby' => intval($orderby),
'active' => $active,
"show_in_menu" => $show_in_menu,
"meta_keywords" => $meta_keywords,
"meta_description" => $meta_description
);

and replace with
Code:


$query_data = array(
'title' => $pagetitle,
'orderby' => intval($orderby),
'active' => $active,
"show_in_menu" => $show_in_menu,
"meta_keywords" => $meta_keywords,
"meta_description" => $meta_description,
"pages_page_title" => $pages_page_title # Added by CFL Systems for static page title
);

in the same file find
Code:


$page_query = "SELECT pageid, filename, title, level, orderby, active, language, show_in_menu, meta_keywords, meta_description, $sql_tbl[clean_urls].clean_url, $sql_tbl[clean_urls].mtime FROM $sql_tbl[pages] LEFT JOIN $sql_tbl[clean_urls] ON $sql_tbl[clean_urls].resource_type = 'S' AND $sql_tbl[clean_urls].resource_id = '".@$clean_url_pageid."' ";

and replace with
Code:


$page_query = "SELECT pageid, filename, title, level, orderby, active, language, show_in_menu, meta_keywords, meta_description, pages_page_title, $sql_tbl[clean_urls].clean_url, $sql_tbl[clean_urls].mtime FROM $sql_tbl[pages] LEFT JOIN $sql_tbl[clean_urls] ON $sql_tbl[clean_urls].resource_type = 'S' AND $sql_tbl[clean_urls].resource_id = '".@$clean_url_pageid."' "; # Modified by CFL Systems for static page title

in the same file find
Code:


$smarty->assign("default_meta_description", $page_modified['meta_description']);

and after it insert
Code:


$smarty->assign("default_pages_page_title", $page_modifier['pages_page_title']); # Added by CFL Systems for static page title


open skin1/admin/main/page_edit.tpl, find
Code:


<tr>
<td height="10" class="FormButton" nowrap="nowrap" valign="top">{$lng.lbl_page_name}:</td>
<td><font class="Star">*</font></td>
<td><input type="text" name="pagetitle" value="{$page_data.title|default:"$default_page_title"}" size="45" {if $config.SEO.clean_urls_enabled eq "Y"}onchange="javascript: if (this.form.clean_url.value == '') copy_clean_url(this, this.form.clean_url)"{/if} /></td>
</tr>

and after it insert
Code:


{* Added by CFL Systems for static page title *}
<tr>
<td height="10" class="FormButton" nowrap="nowrap" valign="top">{$lng.lbl_pages_page_title}:</td>
<td>&nbsp;</td>
<td><input type="text" name="pages_page_title" maxlength="64" size="100" value="{$page_data.pages_page_title|default:"$default_pages_page_title"}" />
<a href="javascript:void(0);" class="NeedHelpLink" onmouseover="javascript: viewHelp('help_what_is_page_title', this);">{$lng.lbl_page_title_what_is}</a>
<div id="help_what_is_page_title" class="NeedHelpBox" style="display:none">{$lng.txt_page_title_descr}</div></td>
</tr>
{* Added by CFL Systems for static page title *}


Continue in the next thread

cflsystems 05-01-2009 06:01 AM

Re: Page Title in 4.2
 
...... from the previous thread

8. MAKE THE NEW TITLES APPEAR
open skin1/customer/service_head.tpl, find
Code:


<title>
..........................
</title>

and replace with
Code:


{* Added by CFL Systems for page titles *}
{if $main eq "catalog" && $current_category.category eq ""}
{assign var="temp_title" value="PUT HERE THE TITLE YOU WANT ON HOME PAGE"}
{elseif $main eq "catalog"}
{assign var="temp_title" value=$current_category.category_page_title}
{elseif $main eq "product"}
{assign var="temp_title" value=$product.product_page_title}
{elseif $main eq "pages"}
{assign var="temp_title" value=$page_data.pages_page_title}
{elseif $main eq "manufacturer_products"}
{assign var="temp_title" value=$manufacturer.manufacturer_page_title}
{else}
{assign var="temp_title" value=""}
{/if}
<title>
{if $temp_title ne ""}
{$temp_title|escape}
{else}
{$html_page_title|escape}
{/if}
</title>
{* Added by CFL Systems for page titles *}


9. Run cleanup.php

That's it. Hope it will work for you. It works for me. I tried to keep it clean and easy to follow. If you have trouble installing it I can do it for you. Enjoy!

HyPeR-X 05-31-2009 12:00 PM

Re: Page Title in 4.2
 
I am having some problems with the above modifications. I have followed all steps, but now when I want to edit a product it x-cart tells me to fill in all fields. But all are already filled in.

Can anyone tell me what I do wrong?

cflsystems 05-31-2009 12:35 PM

Re: Page Title in 4.2
 
What kind of errors?


All times are GMT -8. The time now is 04:54 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.