我在phtml中有两个变量,并希望将它们作为链接。
<?php
$_reviewCount = $_ratingSummary->getReviewsCount();
$_reviewUrl=$_product->getRequestPath().'#reviews';
<!--Here if review count is 1 i want to show as "Review" else "Reviews" -->
<?php echo $_reviewCount ?>
<?php echo "<a href='".$_reviewUrl."'>Review</a>" ?>
<?php ($_reviewCount == 1 ) ? __('Review') : __('Reviews') ?>
但上面只显示小写的关键字'review'。
答案 0 :(得分:0)
只需重写代码,首先定义单数或复数形式,然后回显它:
<?php
if($reviewCount==1){$text='Review';}else{$text='Reviews';}
echo "<a href=\"$_reviewUrl\">$_reviewCount $text</a>";
?>
BTW我会将if条件更改为&gt; 1,因为如果评论次数为0,您的代码会回复评论。
<?php
if($_reviewCount>1){$text='Reviews';}else{$text='Review';}
echo "<a href=\"$_reviewUrl\">$_reviewCount $text</a>";
?>