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
Thanks David
That works, if I now wanted to ad my own to category pages, where would I go to do this?
Cheers
Stuart
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
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
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
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
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
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
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
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.
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
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