You are here:  » SEO: Meta data and content bloc per category


SEO: Meta data and content bloc per category

Submitted by lomic1 on Thu, 2011-03-03 13:08 in

Hi,

I'm new to Price Tapestry and I wonder how to tackle with SEO.

How to manage meta datas for my pages (title, description, keywords, rel canonical...)
I also wonder how I can add a bunch of text on each page. I want this text to be related to the category, the product, the brand, the merchant... The idea here is to add original content to my pages in addition to texts from feeds.

Many thanks

Lomic

Submitted by support on Thu, 2011-03-03 13:46

Hi Lomic,

Meta tags are set throughout the script by setting the $header["meta"] array. For example, take a look in products.php at line 66 where you'll find this code:

      $header["meta"]["description"] = translate("Price search results for")." ".htmlentities($q,ENT_QUOTES,$config_charset);

Any meta tags can be set in that way, as long as they occur before the call to require("html/header.php"); in the same file.

So, let's say you want to set the title, description and keywords meta tags for your home page, edit index.php and look for the following code at line 4:

  require("html/header.php");

...and REPLACE that with:

  $header["title"] = "Home page title";
  $header["meta"]["description"] = "Home page meta description";
  $header["meta"]["keywords"] = "home,page,meta,keywords";
  require("html/header.php");

In terms of adding content dynamically related to the page context, how about creating a directory structure on your site starting with the folder content/ and then inside that folder create additional sub-folders called merchant/ brand/ category/ product/. Inside those folders, create .html files with a name exactly matching the item name, plus ".html".

So, to create your own content for the Product Name product, create the following file:

content/product/Product Name.html

Then, in html/product.php, add the following code to the end to display your custom content between the feed product info and the price comparison table:

<?php
  $contentFilename 
"content/product/".$mainProduct["name"].".html";
  if (
file_exists($contentFilename))
  {
    require(
$contentFilename);
  }
?>

Exactly the same approach can be used anywhere that names, merchant names category or brand values are in scope. For example, to add custom category content to the end of page 1 of the search results for Category Name, create the file

content/category/Category Name.html

Then in html/searchresults.php, add the following code at the end:

<?php
  
if (($page == 1) && ($parts[0] == "category"))
  {
    
$contentFilename "content/category/".$q.".html";
    if (
file_exists($contentFilename))
    {
      require(
$contentFilename);
    }
  }
?>

If you're not sure how to access the parameters at any particular location, let me know where about and what you'd like to display and I'll work the code out for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by lomic1 on Fri, 2011-03-04 08:55

Thank you very much David.
It looks clear so far. Let's try to do something on my own before I bother you again.
But could you just give me one more clue.

Regarding my meta tags and contextual content files, I'd like to set a sort of common structure for each template of my site.

i.e.: product pages template
$header["title"] = "Compare [product name] prices";
$header["meta"]["description"] = "Comparez prices for all [product name] available at our merchants store";
Content file text:
"Here are all [product name] prices. [product name] are part of [category name] category. Compare price of [product name] and find the best offer. Etc"

i.e.: category pages template
$header["title"] = "Compare prices from all products related to [category name]";
Content file text:
"Here are all products related to [category name]. In [category name], compare price of [product name1, product name2] for instance. [merchant name1, merchant name 2] products are available at [mywebsite name]. Compare prices and find the best offer. Etc"

Regarding merchant name 1 and merchant name 2, i'd like to extract the 2 first ones for instance, not all.

I'd like to be able to set up a common structure at the start (keep it simple, I've loads of other things to do) but want to keep the ability to set specific meta tags and contextual content if required for SEO purpose.

So the idea would be if content/category/".$q.".html exists => require content file, if not, require common structure as described above.

And as you can guess I have no PHP knowledge!

Many thanks

Lomic

Submitted by support on Fri, 2011-03-04 09:54

Hi Lomic,

For the product content example, here's how to make a generic content unit when no merchant specific one exists:

<?php
  $contentFilename 
"content/product/".$mainProduct["name"].".html";
  if (
file_exists($contentFilename))
  {
    require(
$contentFilename);
  }
  else
  {
    require(
"content/product/generic.html");
  }
?>

Create your content/product/generic.html file, and within that, simply use:

<?php
 
print $mainProduct["name"]; 
?>

...wherever you want to refer to the merchant name, for example:

Here are all <?php print $mainProduct["name"]; ?> prices. <?php print $mainProduct["name"]; ?> are part of <?php print $mainProduct["category"]; ?> category. Compare price of <?php print $mainProduct["name"]; ?> and find the best offer. Etc"

For a generic category results page content module, it's a little more complicated in terms of pulling in a selection of merchants. Have a go with something like this:

<?php
  
if (($page == 1) && ($parts[0] == "category"))
  {
    
$contentFilename "content/category/".$q.".html";
    if (
file_exists($contentFilename))
    {
      require(
$contentFilename);
    }
  }
  else
  {
    require(
"content/category/generic.html");
  }
?>

This time, create content/category/generic.html containing something like;

Here are all products related to <?php print $parts[1]; ?>. In <?php print $parts[1]; ?>, compare price of <?php print $searchresults["products"][0]["name"]; ?>, <?php print $searchresults["products"][1]["name"]; ?> for instance. <?php print $searchresults["products"][0]["merchant"]; ?>, <?php print $searchresults["products"][1]["merchant"]; ?> products are available at [mywebsite name]. Compare prices and find the best offer. Etc

In both cases, to pull the product name or query into the meta tags, use $q within htmlentities() exactly as currently in search.php (line 320) and products.php (line 66).

Cheers,
David.
--
PriceTapestry.com

Submitted by pieter on Tue, 2012-07-10 11:17

Hi David,

I really like the idea of using content blocks. I would like to use them on category pages only.
Can you give me some pointers on how to implement that?

I tried something like this:

<?php
      
require("html/content/".$q.".html");
 
?>

But that generates category:Categoryname in the URL, so maybe I need to strip something.

Cheers,

Pieter.

Submitted by support on Tue, 2012-07-10 12:29

Hi Pieter,

For category search result pages only, you can look for "category" in $parts[0] and then the category name is in $parts[1], e.g.

<?php
  
if ($searchresults["numRows"] && ($parts[0]=="category"))
  {
    require(
"html/content/".$parts[1].".html");
  }
?>

If you want to restrict the content to page 1 of the results to avoid any duplicate content issues; use:

<?php
  
if ($searchresults["numRows"] && ($parts[0]=="category") && ($page==1))
  {
    require(
"html/content/".$parts[1].".html");
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by pieter on Tue, 2012-07-10 13:23

That works perfect, thank you very much!

Submitted by crounauer on Wed, 2018-12-19 17:24

Hi David,

I'm busy implementng this and have come accross a typo.

$contentFilename = "content/category/".$q.".html";

should read

$contentFilename = "content/category/".$parts[0].".html";

Thanks for the brilliant mods!

Simon

Submitted by paullas on Thu, 2021-12-23 18:08

Hi David

I am trying to re implement the above so when a certain category is displayed it pulls from a html file, so for example if the visitor goes to site/category/70th-Birthday-Gifts/ then in the content/ folder what ever content i put in 70th-Birthday-Gifts.html is displayed on that page.

For some reason it is not pulling the content in.

The code i am using as above is the following in the searchresults.php

<?php
  
if (($page == 1) && ($parts[0] == "category"))
  {
    
$contentFilename "content/category/".$q.".html";
    if (
file_exists($contentFilename))
    {
      require(
$contentFilename);
    }
  }
  else
  {
    require(
"content/category/generic.html");
  }
?>

Any ideas why this is not working.

thanks

Paul

Submitted by support on Fri, 2021-12-24 11:18

Hello Paul,

$parts[1] will contain the category name ($q includes the category: prefix) so it should work as expected using:

    $contentFilename = "content/category/".$parts[1].".html";

Cheers,
David.
--
PriceTapestry.com

Submitted by paullas on Fri, 2021-12-24 13:54

Hi David

Must be something im doing, below is what i have.

{link saved}

in searchresults.php i have:

<?php
  
if (($page == 1) && ($parts[0] == "category"))
  {
$contentFilename "content/category/".$parts[1].".html";
    if (
file_exists($contentFilename))
    {
      require(
$contentFilename);
    }
  }
  else
  {
    require(
"content/category/generic.html");
  }
?>

and i have a file called Retirement-Gifts.html in the content/category folder

thanks

paul

Submitted by support on Fri, 2021-12-24 14:13

Hi Paul,

Ah - the hyphens are removed in the value in $parts[1]. Either; rename your files so they don't include the hyphen e.g.

Retirement Gifts.html

Alternatively, if you'd prefer to use hyphens in the filenames, use:

$contentFilename = "content/category/".tapestry_hyphenate($parts[1]).".html";

Cheers,
David.
--
PriceTapestry.com

Submitted by paullas on Fri, 2021-12-24 14:19

your a star David :) bloody hyphes lol

thank you