开发者

What to add to PHP if statment to display certain text?

开发者 https://www.devze.com 2023-02-03 19:41 出处:网络
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 tha

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; ?>

0

精彩评论

暂无评论...
验证码 换一张
取 消