You are here:  » Adding product tags and displaying pages containing respective products

Active Forum Topics

Adding product tags and displaying pages containing respective products

Submitted by bat on Fri, 2014-07-25 13:20 in

Hi David,
I've got an idea and I wondered if it's possible.

I've got a category of products but that category is so general that I want to make subcategories but I know thats not possible within the standard script.

However, I wondered if there was a way to add to product mapping an option for 'Tags', where we could write in, seperated by a comma, more specific terms for the product.
As well a Tags field would be good in the Register Feed section in case feeds already come with fields that would work as tags.

Then the tags can be used to summon up custom 'subcategory' style pages within the site.

I know at the moment there's an option to create custom pages using the search function or product name, etc, but the keywords that I want don't exist in product names. It's something that I'd have to apply to the product afterwards.

E.g. Category is 'Clothing' but I want to create a sub category for clothing for different seasons. Therefore I would like to product map some products and write in the tag 'Summer' or 'Winter'.

Then I would like to be able to create a custom page that will pull all the results that match my chosen tag which i have mapped i.e. Summer.

I hope you kind of get my idea, and is it possible please?


Submitted by support on Fri, 2014-07-25 13:49

Hello bat,

Sure - the first step would be to add a new custom field "tags" as per the standard instructions, but rather than base your dbmod.php script on the first post instead use the instructions in this comment for adding a custom field for which you can also manually enter a value via Product Mapping.

With that in place, you can then add a search handler for tag: as follows. In search.php look for the following code at line 194:

      case "bw":

...and REPLACE with:

      case "tag":
        $where = "tags LIKE '%".database_safe($parts[1])."%'";
        $sql = "SELECT SQL_CALC_FOUND_ROWS id,COUNT(id) AS numMerchants,MIN(price) as minPrice FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere." GROUP BY search_name";
        $orderBySelection = $orderByDefault;
      case "bw":

You'll then be able to search by, for example, tag:Widget

Once all up and running, displaying the tag list on the product page with each tag being a link to the tag: search results is no problem. Within html/product.php (13/03A) at the point at which you'd like to display the tag list, have a go with something like:

if ($mainProduct["tags"])
$tags explode(",",$mainProduct["tags"]);
$tags as $tag)
$tag trim($tag);
"<li><a href='".$config_baseHREF."search.php?q=tag:".urlencode($tag)."'>".$tag."</a></li>";


Submitted by bat on Fri, 2014-07-25 23:01

Thanks David.
I've done as you said and then used this page to modify the Product Mapping code so there's a box to enter tags.
I added a new field called tags in the product mapping table of my database too, so at least now when I add a tag to a mapped product it saves.

In each instance, I've used the term tags

I've done everything else you said but when I type in tag:Summer Season, for example, nothing comes up, even though Summer Season is the tag for two products.

Submitted by support on Sat, 2014-07-26 14:52

Hello bat,

Did the final code snippet above successfully display the tag list on your product page (or are you otherwise able to verify that the `tags` field is being populated as expected), or is it only search that does not appear to be working?


Submitted by bat on Sat, 2014-07-26 18:09

I did use the code you provided in the html/product page (even though I'm using 12/10B patched from 12/10A) but nothing appeared.

Looking at the database, the tags are showing up in product mapping table. Should they elsewhere?

Submitted by support on Sun, 2014-07-27 09:46

Hello bat,

Yes, they should be appearing in `pt_products.tags` having been applied by the Product Mapping code during import. If you could please email me your modified includes/admin.php I'll check that part of it out right away for you...