Hi David
I have used the following code in product.php to drive traffic to retailer reviews:
<?php foreach($prices["products"] as $product): ?>
<li><a href='<?php print tapestry_buyURL($product); ?>' target="_blank"> Read customer reviews</a> at <?php print $product["merchant"]; ?>, <?php print $config_currencyHTML.number_format(sprintf("%.2f",($product["price"]+$product["delcost"])),2); ?></li>
<?php endforeach; ?>
In a few instances,however, some retailers do not have reviews.
If I have 10 merchants and Merchant A, Merchant D and Merchant F do not have reviews, how could I amend the above loop to alter the link description from "Read customer reviews" to "More information available"?
Many thanks
Richard
Hi Richard,
The easiest way is to create an array containing your exceptions, and then check that array in each itteration to decide which text to use. Have a go with something like this...
<?php $noReviews = array("Merchant A","Merchant D","Merchant F"); ?>
<?php foreach($prices["products"] as $product): ?>
<li><a href='<?php print tapestry_buyURL($product); ?>' target="_blank"><?php print (in_array($product["merchant"],$noReviews)?"More information available":"Read customer reviews"); ?></a> at <?php print $product["merchant"]; ?>, <?php print $config_currencyHTML.number_format(sprintf("%.2f",($product["price"]+$product["delcost"])),2); ?></li>
<?php endforeach; ?>
The code structure used in the print statement (condition:then:else) is called a ternary, and basically a short form of an if/then/else statement...
Cheers,
David.