You are here:  » Title tags on category pages


Title tags on category pages

Submitted by JasonG on Wed, 2011-11-02 15:51 in

Hi David

I am assuming that Title tags on category pages are crated based on what the category name is when it's set-up

I also note that it has the word category: in frot of the name, was there a reason for implementing that?

Can yo point me in the right direction of being able to change the Title tags on each category page to something unique?

Cheers
Stuart

Submitted by support on Wed, 2011-11-02 16:37

Hi Stuart,

Title tags on category pages are generated by search.php which by default shows the query as the title which for a category search is category:Category Name however it's straight forward to remove this (and merchant: and brand:). In that file, look for the following code at line 320:

    $header["title"] = htmlentities($q,ENT_QUOTES,$config_charset);

...and REPLACE with:

    $header["title"] = htmlentities($q,ENT_QUOTES,$config_charset);
    $header["title"] = str_replace(array("merchant:","category:","brand:",":"),"",$header["title"]);

Cheers,
David.
--
PriceTapestry.com

Submitted by JasonG on Thu, 2011-11-03 14:37

Thanks David

That works, if I now wanted to ad my own to category pages, where would I go to do this?

Cheers
Stuart

Submitted by support on Thu, 2011-11-03 15:12

Hi Stuart,

Immediately after the above code you could override completely for category search results using:

  if ($parts[0]=="category")
  {
    $header["title"] = "Your title here";
  }

At this point, the category name is in $parts[1], so you could use it as follows:

  if ($parts[0]=="category")
  {
    $header["title"] = "Here are ".htmlentities($parts[1],ENT_QUOTES,$config_charset);." search results";
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by JasonG on Fri, 2011-11-11 14:46

Hi David

I have not implemented the above yet, I think what you provded would give me a generic Title tag on all category pages, of am I mistaken?

1. What I need is to find a way to put unique title tags in for every category, ideally that I can type in myself. Can this be done?

2. We will also want to do every product page, but plan to automate this somehow, maybe by detecting what the products is and what category it is in then have the | product name | categoy name | brand | compare prices | our company name |
Can this be done?

Thanks
Stuart

Submitted by support on Fri, 2011-11-11 16:27

Hi Stuart,

If you want the category name in your custom title tags the second example is the one to use - sounds like exactly what you want (category name is in the $parts[1] variable) e.g.

  if ($parts[0]=="category")
  {
    $header["title"] = "Here are ".htmlentities($parts[1],ENT_QUOTES,$config_charset);." search results";
  }

(the reason it's wrapped in a call to htmlentities() is to make sure that quotes etc. in the category name (although there shouldn't be) don't interfere with the HTML markup.

Similar can be done on the product page. The default title tag is creating using the following code at line 64:

$header["title"] = htmlentities($q,ENT_QUOTES,$config_charset);

So for your example, incorporating category and brand I would actually use something like the following, so that incase a product doesn't have a category and/or brand you don't end up with blanks between | characters!

$header["title"] = htmlentities($q,ENT_QUOTES,$config_charset);
if ($product["products"][0]["category"]) = $header["title"] .= " | ". htmlentities($product["products"][0]["category"],ENT_QUOTES,$config_charset);
if ($product["products"][0]["brand"]) = $header["title"] .= " | ". htmlentities($product["products"][0]["brand"],ENT_QUOTES,$config_charset);
$header["title"] .= " | Compare Prices | Your Company Name";

Cheers,
David.
--
PriceTapestry.com

Submitted by bat on Tue, 2012-05-01 17:07

Hi David
I've been trying this out but when I get to putting in the code to show the category and brand code, it screws up my page and makes it blank. If I remove the " quotes and replaces with ' around the htmlentities section, the pages appear but the htmlentities code shows up in the title. Not quite sure what I'm doing wrong. I'm using the latest version of PT

Submitted by support on Wed, 2012-05-02 07:30

Hello bat,

There were some closing brackets missing from the above example (corrected) - please have a go with:

$header["title"] = htmlentities($q,ENT_QUOTES,$config_charset);
if ($product["products"][0]["category"]) = $header["title"] .= " | ". htmlentities($product["products"][0]["category"],ENT_QUOTES,$config_charset);
if ($product["products"][0]["brand"]) = $header["title"] .= " | ". htmlentities($product["products"][0]["brand"],ENT_QUOTES,$config_charset);
$header["title"] .= " | Compare Prices | Your Company Name";

Cheers,
David.
--
PriceTapestry.com

Submitted by bat on Tue, 2012-05-15 22:07

I have

if ($parts[0]=="brand")
  {
    $header["title"] = My websites search results for ".$parts[1];
  }

for brand, category and merchant search pages. But if someone doesn't choose any of those and actually does a custom search, what code do I need to do the above but using the search terms as the variable? I'd like to do that for both title and meta description.

e.g. search for waterproof black jacket
title says "my website search results for waterproof jacket"

Thanks

Submitted by support on Wed, 2012-05-16 09:01

Hi bat,

If the search is for a merchant, category or brand then the keyword (merchant/brand name etc) is in $parts[1] as you are using; whereas for a normal search it is in $parts[0]; so the most straight forward thing to do would be to use PHP's "ternary" construct which is basically a mini if/then/else statement - have a go with just:

$header["title"] = My websites search results for ".($parts[1]?$parts[1]:$parts[0]);

(don't forget to remove your if ($parts[0]=="brand") construct)

Cheers,
David.
--
PriceTapestry.com

Submitted by bat on Wed, 2012-05-16 09:40

Hi David, it isn't working... I currently have this:

if ($parts[0]=="category")
  {
    $header["title"] = "My websites search results for ".$parts[1];
  }
  if ($parts[0]=="brand")
  {
    $header["title"] = "My websites search results for ".$parts[1];
  }
  if ($parts[0]=="merchant")
  {
    $header["title"] = "My websites search results for ".$parts[1];
  }

I tried adding that code you just said, I also tried removing all the above code and replacing with the code you just gave but it left the page website search page blank when loaded.
I tried

if ($parts[0]==$q)
  {
    $header["title"] = "My websites search results for ".$parts[1];
  }

but that didn't work either.

Submitted by support on Wed, 2012-05-16 11:16

Sorry Bat,

I missed the $ off $header["title"] - corrected above; have a go with:

$header["title"] = My websites search results for ".($parts[1]?$parts[1]:$parts[0]);

Cheers,
David.
--
PriceTapestry.com