You are here:  » Brands Meta Keywords

Support Forum



Brands Meta Keywords

Submitted by crounauer on Thu, 2011-08-25 20:18 in

I have just modified the standard PT code for creating random brand meta keywords and thought I would share the code. Useful, if like me you have multiple installations of PT running to create unique meta keywords. It can also be adapted for the meta descriptions if needed.

Find this code in brands.php

 if (database_querySelect($sql,$rows))
  {
    foreach($rows as $product)
    {
      if ($product["brand"])
      {
        $item = array();
        $item["name"] = $product["brand"];
        if ($config_useRewrite)
        {
          $item["href"] = urlencode(tapestry_hyphenate($product["brand"]))."/";
        }
        else
        {
          $item["href"] = "search.php?q=brand:".urlencode($product["brand"]).":";
        }
        $atoz["items"][] = $item;
      }
    }
  }
  $banner["h2"] = "<strong>".translate("Brand")." A-Z</strong>";

and change it to this...

 if (database_querySelect($sql,$rows))
  {
    foreach($rows as $product)
    {
      if ($product["brand"])
      {
        $item = array();
        $item["name"] = $product["brand"];
        if ($config_useRewrite)
        {
          $item["href"] = urlencode(tapestry_hyphenate($product["brand"]))."/";
        }
        else
        {
          $item["href"] = "search.php?q=brand:".urlencode($product["brand"]).":";
        }
        $atoz["items"][] = $item;
$metas[] = $item;
      }
    }
  }
  $banner["h2"] = "<strong>".translate("Brand")." A-Z</strong>";
  // Create an array for brand keywords
  shuffle($metas); // randomise the $items array
  $header["title"] = "Meta title goes here";
  $header["meta"]["description"] = "Meta description goes here";
  $header["meta"]["keywords"] = "keyword1, keyword2, ";
  // Generate random keywords
  $i = 0;
  foreach($metas as $key) {
    $header["meta"]["keywords"] .= " ".htmlentities(ucwords($key["name"]),ENT_QUOTES,$config_charset);
    $i++;
    if ($i==10) break; // change for different number of random items
  }

Hope this hasn't been included in the latest release which I haven't had time to look at yet.