You are here:  » Display category fields on product page

Support Forum



Display category fields on product page

Submitted by babrees on Sat, 2011-06-04 07:51 in

Hi David

How would I go about displaying the category and my custom merchant-category fields on the product page please?

TIA
Jill

Submitted by support on Sat, 2011-06-04 08:33

Hi Jill,

Within the main body of html/product.php you can refer to the main category using $mainProduct["category"] and any other custom fields using the exact name as the field exists in the products table, e.g. $mainProduct["merchant_category"], so to display both below the description, look for the following code around line 12:

        <?php if ($mainProduct["description"]): ?>
          <p><?php print $mainProduct["description"]; ?></p>
        <?php endif; ?>

...and use the same structure for the category and any custom fields, e.g.;

        <?php if ($mainProduct["description"]): ?>
          <p><?php print $mainProduct["description"]; ?></p>
        <?php endif; ?>
        <?php if ($mainProduct["category"]): ?>
          <p>Category: <?php print $mainProduct["category"]; ?></p>
        <?php endif; ?>
        <?php if ($mainProduct["merchantcategory"]): ?>
          <p>Category: <?php print $mainProduct["merchantcategory"]; ?></p>
        <?php endif; ?>

If you're not quite sure what your custom fields are named in the database, you could add some temporary debug code at the above point to print out the contents of $mainProduct:

<?php
  print_r
($mainProduct);
?>

That will output the full $mainProduct record array in a readable format of "fieldname" => "value" pairs, so it's the appropriate "fieldname" that you need to use...

Cheers,
David.
--
PriceTapestry.com