I'm looking to find the html on the product display page...i've looked everywhere by can't find it!
I'm also looking to edit the meta title for category and search result pages (to remove the category: part) and also add meta descriptions to category pages, product pages and the homepage.
great script by the way :)
Also, when you update this script, do you do a list of changes so that i can use a file compae program? I seem to modding bits and pieces...
Sorry, i'm not really following. I guess i could set up a clause on the header.php to check if on the frontpage and set the title accordingly...
<title>
<?php if ($_SERVER["PHP_SELF"] == "/index.php"){print " My main title goes here";} else {
<?php print (isset($header["title"])?$header["title"]:$config_title); ?>
}
</title>
But i would like to set the category titles to:
category name - site name
and product titles to:
product name - category name
How could i go about that?
And same goes with the meta description and keywords :)
Hi,
You could make the changes in header.php, but it's probably easier to make them in the individual files that set the variables that are then displayed as the title, meta tags etc.
Just to explain how it works a little further; looking back at the code you have on line 50 of products.php:
$header["title"] = $q;
Within html/header.php, the title is then displayed using the following code:
<title><?php print (isset($header["title"])?$header["title"]:$config_title); ?></title>
In other words - if there is a value in $header["title"] then use it as the title; otherwise use the site default title as set in config.php
Now, because on the product page, the value of the $q variable contains the product name; this means that the title of the page will just be the product name.
So, to make the title become the product name - category; you need to write some code to construct the appropriate title value; and then assign it to $header["title"] in products.php.
At line 50, the category of the product is in the following variable:
$product["products"][0]["category"]
Therefore, to construct the title value as you would like it, the following code would do the trick:
$header["title"] = $q . " - ".$product["products"][0]["category"];
In exactly the same way you can control the meta keywords and description tags - they're set on the next 2 lines - but let me know if you'd like any more help in setting those.
Your category page title "category name - site name" is a little more complicated because the page is actually generated by search.php and not a specific category search page.
In this case, $header["title"] is set on line 131. What i'd do here is change this code so that the title is set depending upon the type of search (of which category is one), so change the code as follows:
if ($parts[0] == "category")
{
$header["title"] = $parts[1]." - Your Site Name Here";
}
else
{
$header["title"] = $q;
}
This works because the category name is in the $parts[1] variable when $parts[0] is "category".
Hope this helps!
Cheers,
David.
Hi David,
I'm looking in products.php and not finding the code on line 50 you say to change...
Hiya,
Sorry - it's actually a bit confusing in the post above having re-read it. The actual code on line 50 is:
$header["title"] = $q;
That's where you need to make the changes to change the title....
Cheers,
David.
Ok, cool, i now have the products and category titles sorted. :)
Where would i edit to set the category page desc and keyw?
Also where would i set the homepage desc and keyw?
Hiya,
To set the the description and keyword meta tags on the category page, add the following code immediately before require("html/header.php"); in categories.php:
$header["meta"]["description"] = "Your description here.";
$header["meta"]["keywords"] = "Your,Keywords,Here";
For the homepage, do exactly the same in index.php - again inserting the code above immediately before the following line:
require("html/header.php");
Cheers,
David.
Nearly there! Got the index sorted. Just can't get the categories.php to display them:
$header["meta"]["description"] = $product["category"];
$header["meta"]["keywords"] = $product["category"];
This isn't working for me...sorry my php is still basic i'm afraid! Tried with quotes and without.
Hi,
On categories.php the $product variable doesn't exist which is why the above code doesn't work. On this page; you will need to hard code the description and keywords as required, for example:
$header["meta"]["description"] = "Description for categories page."
$header["meta"]["keywords"] = "Keywords,For,Categories,Page";
You would only be able to display an actual product category on the products page...
Hope this helps,
Cheers,
David.
Ah, that's no good then, as i need these to change according to the category. Can it not be achieved using the search page as with the title?
Hiya,
The individual category pages are actually displayed by the search.php script. Have another look at the 3rd message in this thread - there's some code there for detecting a category search in search.php and changing the title tag as required.
To set the meta title and description as well; you can change the code at that point as follows (remember that the current category is in $parts[1]):
if ($parts[0] == "category")
{
$header["title"] = $parts[1]." - Your Site Name Here";
$header["meta"]["description"] = "Your ".$parts[1]." description here.;
$header["meta"]["keywords"] = "Your,".$parts[1].",Keywords,Here";
}
else
{
$header["title"] = $q;
}
Cheers,
David.
Sorry, yes i have already done the title using search.php as stated in his thread :)
Using your code i have done this, which seems to work as desired:
$header["meta"]["description"] = $parts[1];
$header["meta"]["keywords"] = $parts[1];
If i wanted to repeat the same for the brands.php, is this done in search.php as well?
Sure - just add another if condition using elseif....
if ($parts[0] == "category")
{
$header["title"] = $parts[1]." - Your Site Name Here";
$header["meta"]["description"] = "Your ".$parts[1]." description here.;
$header["meta"]["keywords"] = "Your,".$parts[1].",Keywords,Here";
}
elseif ($parts[0] == "brand")
{
$header["title"] = $parts[1]." - Your Site Name Here";
$header["meta"]["description"] = "Your ".$parts[1]." description here.;
$header["meta"]["keywords"] = "Your,".$parts[1].",Keywords,Here";
}
else
{
$header["title"] = $q;
}
Again, in the case of the brand section $parts[1] contains the current brand.
Cheers,
David.
Hi,
The title and meta tags are set on line 50 of products.php as follows:
$header["title"] = $q;
$header["meta"]["description"] = translate("Price search results for")." ".htmlentities($q,ENT_QUOTES,$config_charset);
$header["meta"]["keywords"] = htmlentities($q,ENT_QUOTES,$config_charset);
The values in the $header array are then picked up and displayed by html/header.php....
As Price Tapestry has been stable for quite some time now I don't do updates very often, but yes - whenever I do I post which files have changed so that you only need to update the newer files (or merge the changes into your current site)
Cheers,
David.