_collection = $collection; $this->_collection->setCurPage($this->getCurrentPage()); // we need to set pagination only if passed value integer and more that 0 $limit = (int)$this->getLimit(); if ($limit) { $this->_collection->setPageSize($limit); } if ($this->getCurrentOrder()) { $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection()); } return $this; } /** * Return products collection instance * * @return \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection */ public function getCollection() { return $this->_collection; } /** * Get specified posts limit display per page * * @return string */ public function getLimit() { return $this->_scopeConfig->getValue( 'mfblog/post_list/posts_per_page', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } /** * Return current page from request * * @return int */ public function getCurrentPage() { $page = (int) $this->_request->getParam(self::PAGE_PARM_NAME); return $page ? $page : 1; } /** * Render pagination HTML * * @return string */ public function getPagerHtml() { $pagerBlock = $this->getChildBlock('post_list_toolbar_pager'); if ($pagerBlock instanceof \Magento\Framework\DataObject) { /* @var $pagerBlock \Magento\Theme\Block\Html\Pager */ $pagerBlock->setUseContainer( false )->setShowPerPage( false )->setShowAmounts( false )->setPageVarName( 'page' )->setFrameLength( $this->_scopeConfig->getValue( 'design/pagination/pagination_frame', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ) )->setJump( $this->_scopeConfig->getValue( 'design/pagination/pagination_frame_skip', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ) )->setLimit( $this->getLimit() )->setCollection( $this->getCollection() ); return $pagerBlock->toHtml(); } return ''; } }