我使用我的消息插件作为例子,我是参考magento的tag wishlist order如何添加pager代码的。你直接套用本教程中的代码,基本就可以实现给你的插件添加分页的功能了。
在插件block的php文件中
<?php class Hellokeykey_Messagesbox_Block_Messagesbox extends Mage_Core_Block_Template { public function __construct() { parent::__construct(); /*声明我的collection*/ $this->_collection = Mage::getModel('messagesbox/messagesbox')->getCollection(); /*对我的collection进行筛选,我将结果按照建立时间进行了逆向排序,所以最近添加的会显示在前面。并且只显示激活状态的消息*/ $this->_collection ->setOrder('created_time', 'DESC') ->addFilter('status',array('status' => '1')); } public function count() { /* 判断是否为空,在我们的phtml输出前判断下,为空的话说出一段html作为提示 */ return $this->_collection->getSize(); } public function getToolbarHtml() { /* 获得toobar,在phtml中用到 */ return $this->getChildHtml('toolbar'); } protected function _prepareLayout() { /* 定义我们的toobar */ $toolbar = $this->getLayout()->createBlock('page/html_pager', 'messages_messages.toolbar')/* messages_messages.toolbar 是随便写的*/ ->setCollection($this->_getCollection()); $this->setChild('toolbar', $toolbar); return parent::_prepareLayout(); } protected function _getCollection() { return $this->_collection; } public function getCollection() { return $this->_getCollection(); }
在我们的模板文件phtml中
<div id="_mcePaste"><!-- table --></div> <div id="_mcePaste"><?php if($this->count()): /*判断是否为空*/?></div> <div id="_mcePaste"><?php echo $this->getToolbarHtml(); /*获得分页工具条*/?></div> <div id="_mcePaste"><table id="my-messages-table"></div> <div id="_mcePaste"><col width="12%" /></div> <div id="_mcePaste"><col width="68%" /></div> <div id="_mcePaste"><col width="12%" /></div> <div id="_mcePaste"><col width="8%" /></div> <div id="_mcePaste"><thead></div> <div id="_mcePaste"><tr></div> <div id="_mcePaste"><th><?php echo $this->__('Date(m/d/y)') ?></th></div> <div id="_mcePaste"><th><?php echo $this->__('Messages') ?></th></div> <div id="_mcePaste"><th><?php echo $this->__('Download') ?></th></div> <div id="_mcePaste"><th><?php echo $this->__('Link') ?></th></div> <div id="_mcePaste"></tr></div> <div id="_mcePaste"></thead></div> <div id="_mcePaste"><tbody></div> <div id="_mcePaste"><?php foreach ($this->getCollection() as $i=>$message): /* 这里是最重要的地方,一定要用$this->getCollection()来获得Collection */ ?></div> <div id="_mcePaste"><tr></div> <!-- table --><?php if($this->count()): /*判断是否为空*/?> <?php echo $this->getToolbarHtml(); /*获得分页工具条*/?><table id="my-messages-table"> <col width="12%" /> <col width="68%" /> <col width="12%" /> <col width="8%" /> <thead> <tr> <th><?php echo $this->__('Date(m/d/y)') ?></th> <th><?php echo $this->__('Messages') ?></th> <th><?php echo $this->__('Download') ?></th> <th><?php echo $this->__('Link') ?></th> </tr> </thead> <tbody> <?php foreach ($this->getCollection() as $i=>$message): /* 这里是最重要的地方,一定要用$this->getCollection()来获得Collection */ ?> <tr> <pre>
转载表明出处:hellokeykey.com
我想问一下有一个可以写新闻的是怎么搞的?是要添加一个什么模板吗?
应该是用的magento的博客插件,你google下,应该有免费的。magento的cms也可以实现。
用magento的cms该怎么实现?可以具体说说不?
恩,是这样的。我有时间的话,我会录个视频,教大家如何操作cms。但是,如果你不会css和html你不会排版和修饰的,还是行不通的。所以你想自己弄的话,要先学校html和css才行。如果你是只开店,建议你找个人帮你弄下,去magento的QQ群或论坛,很多人会做的。
为什么我照你这样写,系统会提示找不到setCollection() 这个函数,请你帮我分析下是什么原因,
参考下magento的源代码,看下哪里是不是要添上或者删掉这个函数
请问在怎样设置每页显示的个数呢,我已经成功添加了翻页,但是每页显示的个数为默认的10,20,50,请问怎样修改这个数字呢,我在xml里设置100,是不管用的,求助,多谢谢
后台设置 system->configuration->catalog中设置每页显示数量,看下我的视频讲解也好。