Adding code to Header Tags Controller
files for additional pages
The Header Tags Controller contribution comes with the code needed for the
product pages of your site as well as a few additional standard pages. But you
need to code for all of your pages. Otherwise, you are losing the benefit of
this powerful contribution. The following takes you through the process of
adding the code for an About Us page. To add code for a different page, you simply
need to change the name from ABOUT_US to whatever the page name is. Capital
letters is not required but helps when trying to troubleshoot problems so it is
better if you adhere to the convention.
First, there are only two files in the whole Header Tags Controller contribution
that you need ever edit. They are the includes/header_tags.php and includes/languages/english/header_tags.php
file. These are the two files we will be editing here. The procedure changed a little
in version 2.4.0 so two sets of instructions are given here. Use the one that
fits your version.
FOR VERSIONS PRIOR TO V 2.4.0
Editing the includes/languages/english/header_tags.php fileWe'll start with the includes/languages/english/header_tags.php file. If
you view the contents of this file, you will see a number of blocks of
code that are similar to the following:
// index.php
define('HTTA_DEFAULT_ON','1');
define('HTKA_DEFAULT_ON','1');
define('HTDA_DEFAULT_ON','1');
define('HEAD_TITLE_TAG_DEFAULT', '');
define('HEAD_DESC_TAG_DEFAULT','');
define('HEAD_KEY_TAG_DEFAULT','');
To add your code for the About Us page, highlight the above section of code,
paste it in the same file (anywhere is fine as long as it is before the closing ?>
tag), then go through it and replace all occurrences of DEFAULT with ABOUT_US. Your
section of code should end up looking like the following. Notice that I added
About Us in the HEAD_TITLE_TAG_ABOUT_US line. This is what is used for the
title of your page.
// about_us.php
define('HTTA_ABOUT_US_ON','1');
define('HTKA_ABOUT_US_ON','1');
define('HTDA_ABOUT_US_ON','1');
define('HEAD_TITLE_TAG_ABOUT_US','About Us');
define('HEAD_DESC_TAG_ABOUT_US','');
define('HEAD_KEY_TAG_ABOUT_US','');
Editing the includes/header_tags.php file That's it for that file. Now on to the includes/header_tags.php file.
Just like before, open this file and take a look at it. Again, you will see
that there are many blocks of code, all looking similar to this one (note that
the code does not appear exactly as it does in your file due to the formatting
of this page):
// INDEX.PHP - was default.php
case (strstr($_SERVER['PHP_SELF'],FILENAME_DEFAULT) or strstr($PHP_SELF,FILENAME_DEFAULT) ):
$the_category_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . $current_category_id . "' and cd.categories_id = '" . $current_category_id . "' and cd.language_id = '" . $languages_id . "'");
$the_category = tep_db_fetch_array($the_category_query);
$the_manufacturers_query= tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . $HTTP_GET_VARS['manufacturers_id'] . "'");
$the_manufacturers = tep_db_fetch_array($the_manufacturers_query);
if (HTDA_DEFAULT_ON=='1') {
$the_desc= HEAD_DESC_TAG_DEFAULT . ' ' . HEAD_DESC_TAG_ALL;
} else {
$the_desc= HEAD_DESC_TAG_DEFAULT;
}
if (HTKA_DEFAULT_ON=='1') {
$the_key_words= HEAD_KEY_TAG_ALL . ' ' . HEAD_KEY_TAG_DEFAULT;
} else {
$the_key_words= HEAD_KEY_TAG_DEFAULT;
}
if (HTTA_DEFAULT_ON=='1') {
if (empty($the_category['categories_name'])) {
$the_title= HEAD_TITLE_TAG_ALL . ' ' . HEAD_TITLE_TAG_DEFAULT;
} else {
$the_title= $the_category['categories_name'] . $the_manufacturers['manufacturers_name'] . " - " . HEAD_TITLE_TAG_ALL . ' ' . HEAD_TITLE_TAG_DEFAULT;
}
} else {
$the_title= HEAD_TITLE_TAG_DEFAULT;
}
break;
And, again, like above, replace all instances of DEFAULT with ABOUT_US.
After doing that, also remove the following lines of code from the block you
just pasted. These lines are special case situations that normal pages do not use.
$the_category_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . $current_category_id . "' and cd.categories_id = '" . $current_category_id . "' and cd.language_id = '" . $languages_id . "'");
$the_category = tep_db_fetch_array($the_category_query);
$the_manufacturers_query= tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . $HTTP_GET_VARS['manufacturers_id'] . "'");
$the_manufacturers = tep_db_fetch_array($the_manufacturers_query);
The resulting code should look like the following:
// ABOUT_US.PHP - was default.php
case (strstr($_SERVER['PHP_SELF'],FILENAME_ABOUT_US) or strstr($PHP_SELF, FILENAME_ABOUT_US) ):
if (HTDA_ABOUT_US_ON=='1') {
$the_desc= HEAD_DESC_TAG_ABOUT_US . ' ' . HEAD_DESC_TAG_ALL;
} else {
$the_desc= HEAD_DESC_TAG_ABOUT_US;
}
if (HTKA_ABOUT_US_ON=='1') {
$the_key_words= HEAD_KEY_TAG_ALL . ' ' . HEAD_KEY_TAG_ABOUT_US;
} else {
$the_key_words= HEAD_KEY_TAG_ABOUT_US;
}
if (HTTA_ABOUT_US_ON=='1') {
$the_title= HEAD_TITLE_TAG_ABOUT_US . ' ' . HEAD_TITLE_TAG_ALL;
} else {
$the_title= HEAD_TITLE_TAG_ABOUT_US;
}
break;
FOR VERSIONS AFTER V 2.3.9
Editing the includes/languages/english/header_tags.php file
This section is the same for both versions so see above for instructions.
Editing the includes/header_tags.php file
The code for this version was condensed to make adding pages easier. To add an About Us page
with this version, add this code (already included in basic code):
// about_us.PHP - was default.php
case (strstr($_SERVER['PHP_SELF'],FILENAME_ABOUT_US) or strstr($PHP_SELF, FILENAME_ABOUT_US) ):
$tags_array = tep_header_tag_page(HTTA_ABOUTUS_ON, HEAD_TITLE_TAG_ABOUTUS,
HTDA_ABOUTUS_ON, HEAD_DESC_TAG_ABOUTUS,
HTKA_ABOUTUS_ON, HEAD_KEY_TAG_ABOUTUS );
break;
That's it. To add another page, just copy the above and change the ABOUT_US and ABOUTUS
to whatever you want. They just need to match the code you add to includes/languages/english/header_tags.php.
View the resultsThat's it. Save your files, view your About Us page in your browser and
you should see About Us in the title of the browser. If you have any questions
about this tutorial, feel free to
contact us. |