php - 将上一个和下一个按钮添加到类别产品

标签 php jquery html css magento

我使用以下 block 在主页中显示类别产品。 {{block type="catalog/product_list"template="catalog/product/home_short.phtml"category_id="5"column_count="6"}}。现在我需要在产品列表和我的代码中添加上一个和下一个按钮是

<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">

<?php // Grid Mode ?>

<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
    <?php if ($i++%$_columnCount==0): ?>
    <ul class="products-grid">
    <?php endif ?>
        <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135,135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" /></a>
            <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h2>
            <?php echo $this->getPriceHtml($_product, true) ?>
            <div class="actions">
                <?php if($_product->isSaleable()): ?>
                    <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                <?php else: ?>
                    <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                <?php endif; ?>
            </div>
        </li>
    <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
    </ul>
    <?php endif ?>
    <?php endforeach ?>
    <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
</div>
<?php endif; ?>

最佳答案

  1. 转到 CMS > 管理页面并点击主页。
  2. 在“设计”选项卡下,在“更新布局 XML”字段中插入以下代码。

    <reference name="content">
      <block type="catalog/product_list" name="product_list" template="catalog/product/home_short.phtml">
      <action method="setCategoryId"><category_id>5</category_id></action>
      <action method="setCategoryId"><category_id>6</category_id></action>
      <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
      <block type="page/html_pager" name="product_list_toolbar_pager"/>
      </block>
      <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
      </block>
    </reference>
    

magento 根据您的产品数量自动划分页面并使用上一页和下一页按钮设置分页

关于php - 将上一个和下一个按钮添加到类别产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19093278/

相关文章:

javascript - 如何在我的案例中创建加载屏幕

javascript - 使用Firebug调试器解决脚本冲突

javascript - 简单函数在使用 onclick 时触发,在 JS 中使用 addEventListener 时不触发

javascript - IE 输入类型文本奇怪的行为

php - 如何用 php 显示 sphinx 搜索结果?

php - 提交后打开模态窗口并返回页面

php - 使用 PHP 截断 float

jquery - 在 <li> 内单击 <p> 时导航到 <a>

jQuery val() 没有得到实时结果

python - 无法在 Django Flatpages 中使用 {{MEDIA_URL}}?