I have 开发者_开发问答the following statement in magento and was wondering what I need to add to get it to show that if the TotalNum is equal to 1 then it should only show the text 'item' rather than 'item(s)'
<p class="amount">
<?php if($this->getLastPageNum()>1): ?>
<?php echo $this->__('<span class=search-number>%s</span> items found. Showing %s to %s.', $this->getTotalNum(), $this->getFirstNum(), $this->getLastNum()) ?>
<?php else: ?>
<strong><?php echo $this->__('<span class=search-number>%s</span> item(s) found.', $this->getTotalNum()) ?></strong>
<?php endif; ?>
</p>
<?php
$s = $this->getTotalNum() == 1 ? '' : 's';
?>
<p class="amount">
<?php if($this->getLastPageNum()>1): ?>
<?php echo $this->__('<span class=search-number>%s</span> item' . $s . ' found. Showing %s to %s.', $this->getTotalNum(), $this->getFirstNum(), $this->getLastNum()) ?>
<?php else: ?>
<strong><?php echo $this->__('<span class=search-number>%s</span> item' . $s . ' found.', $this->getTotalNum()) ?></strong>
<?php endif; ?>
</p>
You could use:
<p class="amount">
<?php if($this->getTotalNum() == 1): ?>
<?php echo $this->__('<span class=search-number>1</span> item found.') ?>
<?php else if($this->getLastPageNum()>1): ?>
<?php echo $this->__('<span class=search-number>%s</span> items found. Showing %s to %s.', $this->getTotalNum(), $this->getFirstNum(), $this->getLastNum()) ?>
<?php else: ?>
<strong><?php echo $this->__('<span class=search-number>%s</span> items found.', $this->getTotalNum()) ?></strong>
<?php endif; ?>
</p>
This should be close to what you need.
echo ($this->getTotalNum() > 1) 'items' : 'item';
Place that where you wish to have the word item or items echoed. Here is an example.
<p class="amount">
<?php if($this->getLastPageNum()>1): ?>
<?php echo $this->__('<span class=search-number>%s</span> items found. Showing %s to %s.', $this->getTotalNum(), $this->getFirstNum(), $this->getLastNum()) ?>
<?php else: ?>
<strong><?php echo $this->__('<span class=search-number>%s</span> ' . ($this->getTotalNum() > 1) 'items' : 'item' . ' found.', $this->getTotalNum()) ?></strong>
<?php endif; ?>
精彩评论