You are here:  » Category and keywords in title and meta tags

Support Forum



Category and keywords in title and meta tags

Submitted by chrisstaunton on Fri, 2009-02-13 14:55 in

Hi David,

I wonder if you can help me? I'm struggling with two problems on my products.php where trying to set the meta tags.

1. I'd like to be able to show the category of the product - but not the category provided by the data feed, instead the one mapped by my category mapping. In other words, if a product's category has been mapped to another category via the admin tool, show this, otherwise show the one from the feed in the products table.
So the resulting string will take the format:

$header["title"] = Product | Mapped Category

2. Along the same lines, I'd also like to be able to list all of the mapped words in the category as my keywords e.g.

$header["meta"]["keywords"] = Product | Mapped Category | Mapped category associated words

Hope this makes sense.

Many thanks

Chris

Submitted by support on Fri, 2009-02-13 15:05

Hi Chris,

Category mappings are applied at import time; so the category value in the products table will be the mapped category. This code should do the job, in place of the existing title setting (line 50):

$header["title"] = htmlentities($q,ENT_QUOTES,$config_charset)." | ".htmlentities($product["products"][0]["category"],ENT_QUOTES,$config_charset);

A little more code required for the keywords section - try this:

$sql = "SELECT * FROM categories WHERE name='".database_safe($product["products"][0]["category"])."'";
if (database_querySelect($sql,$rows))
{
  $alternates = str_replace("\n","|",$rows[0]["alternates"]);
}
$header["meta"]["keywords"] = htmlentities($q,ENT_QUOTES,$config_charset)." | ".htmlentities($product["products"][0]["category"],ENT_QUOTES,$config_charset)." | ".$alternates;

Cheers,
David.

Submitted by chrisstaunton on Fri, 2009-02-13 15:26

Awesome thanks a lot David, that's great.

Just one very minor point, is there a way I can stop the list being on separate lines? I gathered that's what the str_replace("\n" bit was for, but it's showing in the source code as:

,Plasmas
,Plasma
,Plasma HD TV
,HD Plasma TV

Thank you

Chris

Submitted by support on Fri, 2009-02-13 15:36

Hi Chris,

It can depend what is sent back by the browser when configuring the categories (when the mapping is applied each word is trimmed so both \n and \r would be removed. One of these should do the trick:

  $alternates = str_replace("\r\n","|",$rows[0]["alternates"]);

  $alternates = str_replace("\n\r","|",$rows[0]["alternates"]);

Cheers,
David.