Jump to content
Sign in to follow this  
mhormann

Extend Header Tag Controller for 'extra' pages?

Recommended Posts

Hi everyone.

 

I just did a quick 'hack' to Header Tag Controller (v2.3.7) in order to be able to have some tags on several 'extra' (i.e., static) pages.

 

I'd very much like some feedback from PHP/osC experts, since I'm not so sure if my modifications actually make sense or just increase load times too much.

 

The idea was to have a flexible, language-dependent means of adding some tags to pages like 'conditions.php', 'privacy.php' and some others. As far as I know there is no simple way of declaring constant arrays, so I came up with the following—please comment:

 

In '/catalog/includes/languages/english/header_tags.php', I add this:

// define array of extra pages we want meta information for
unset($HTCE); // unset it first

$HTCE['shipping.php']['HTTA'] = '1'; // Include HEAD_TITLE_TAG_ALL in Title (0=no, 1=yes)?
$HTCE['shipping.php']['HTDA'] = '1'; // Include HEAD_DESC_TAG_ALL in Description (0=no, 1=yes)?
$HTCE['shipping.php']['HTKA'] = '1'; // Include HEAD_KEY_TAG_ALL in Keywords (0=no, 1=yes)?
$HTCE['shipping.php']['HTTT'] = 'Shipping Header Tag Title Text';
$HTCE['shipping.php']['HTDT'] = 'Shipping Header Tag Description Text';
$HTCE['shipping.php']['HTKT'] = 'Shipping Header Tag Key Text';

$HTCE['privacy.php']['HTTA'] = '1';
$HTCE['privacy.php']['HTDA'] = '1';
$HTCE['privacy.php']['HTKA'] = '1';
$HTCE['privacy.php']['HTTT'] = 'Privacy Page Title';
$HTCE['privacy.php']['HTDT'] = 'Privacy Page Description';
$HTCE['privacy.php']['HTKT'] = 'Privacy Page Keywords';

 

In '/catalog/includes/header_tags.php', I modify the 'case ... default' as follows:

// ALL OTHER PAGES NOT DEFINED ABOVE
 default:
   $found_extra = false;
   // Any extra pages defined in 'includes/languages/<language>/header_tags.php'?
   if (is_array($HTCE)) {
     // Yes, go check
     foreach ($HTCE as $the_filename => $the_extra) {
       // Is it this page?
       if (strstr($_SERVER['PHP_SELF'],$the_filename) or strstr($PHP_SELF,$the_filename)) {
         // We're it, go ahead
         $found_extra = true;
         // Make title
         $the_title = ($the_extra['HTTA'] == '1') ? $the_extra['HTTT'] . ' - ' . HEAD_TITLE_TAG_ALL : $the_extra['HTTT'];
         // Make Description
         $the_desc = ($the_extra['HTDA'] == '1') ? $the_extra['HTDT'] . ' ' . HEAD_DESC_TAG_ALL : $the_extra['HTDT'];
         // Make Keywords
         $the_key_words = ($the_extra['HTKA'] == '1') ? $the_extra['HTKT'] . ' ' . HEAD_DESC_TAG_ALL : $the_extra['HTKT'];
         break;
       }
     }
   }
   if (!$found_extra) {
     // None of the above cases, and no 'extra' page, go for the defaults
     $the_desc = HEAD_DESC_TAG_ALL;
     $the_key_words = HEAD_KEY_TAG_ALL;
     $the_title = HEAD_TITLE_TAG_ALL;
   }
   break;

 

To my eyes it looks like a simple and flexible solution, but what do you think?

 

Looking forward to your input,

Matthias


I don't want to set the world on fire—I just want to start a flame in your heart.

 

osCommerce Contributions:

Class cc_show() v1.0 – Show Credit Cards, Gateways

More Product Weight v1.0

Share this post


Link to post
Share on other sites

I have the Meta Tag Controller contrib (similar to Header Tag Controller) installed, and after viewing some strange Google page results, I'm thinking I should not have added the auto-keywords .php include to every page like I've done. :)

 

I was going to post a question on this, but your post seems to validate my thought that I should probably remove the include for it from most pages.

 

And adding something like this (your idea) sounds great for those "extra" pages.

 

As for parse times, running through a tiny array like this and not touching the db at all, will not increase parse times by any significant amount.

 

Thanks for the idea!

Share this post


Link to post
Share on other sites

I've made a few updates since... will post them later on.

 

In the meantime, just be sure NOT to be too ambigous: The example using "shipping.php" is actually BAD! Since we do a simple 'strstr()' for the match, it would also catch "checkout_shipping.php"!

 

(Not much of a problem actually, just name the array key "/shipping.php"...)

 

And, yes: Be sure WHAT you put in the "all keys" and "all descriptions" if you append them using HTDA or HTKA = '1'.

 

<OFFTOPIC>

 

The description shouldn't get longer than about 180-255 characters, the keys also need some watching. There's different opinions on this, some say up to 900-1024 characters is okay, some say "don't put more than 9 well-crafted keywords in"... YOUR decision.

 

To MY opinion, an "auto-keywords" generator must be VERY well crafted if you don't want to get punished by the SEs. And actually, if your content is rich enough, there should be no problem whatsoever. Just remember you CAN modify stylesheets and you CAN use H2..H4 and EM and STRONG in product descriptions... ;-) But don't overdo it. Too much keyword density gets you punished.

 

</OFFTOPIC>

 

For those who are not yet so experienced: If you define 'extra pages' like above said, don't forget to put the code in the page, i.e. modify for example '/catalog/shipping.php' like this:

 

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<?php
// START: Header Tags Controller
// Replaced by header_tags.php
if ( file_exists(DIR_WS_INCLUDES . 'header_tags.php') ) {
 require(DIR_WS_INCLUDES . 'header_tags.php');
} else {
?> 
<title><?php echo TITLE; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<?php
}
// END: Header Tags Controller
?>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>

 

This EXAMPLE does include some lines that are there before and need NOT be changed! It is just an example to show you where to modify what.

 

Enjoy!

Matthias


I don't want to set the world on fire—I just want to start a flame in your heart.

 

osCommerce Contributions:

Class cc_show() v1.0 – Show Credit Cards, Gateways

More Product Weight v1.0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×