In Your .phtml
file :-
<?php if ($block->getPagerHtml()): ?>
<div class="order-products-toolbar toolbar bottom"><?php echo $block->getPagerHtml(); ?></div>
<?php endif ?>
Block file :-
<?php
namespace Vendor\Module\Block;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\View\Element\Template;
class ClassName extends \Magento\Framework\View\Element\Template
{
protected $YourFactory;
protected $_storeManager;
public function __construct(Template\Context $context,
StoreManagerInterface $storeManager,
\Vendor\Module\Model\YourFactory $YourFactory,
array $data = [])
{
$this->YourFactory=$YourFactory;
$this->_storeManager = $storeManager;
parent::__construct($context, $data);
}
public function _prepareLayout()
{
parent::_prepareLayout();
$this->pageConfig->getTitle()->set(__('Your Title'));
if ($this->getTestimonials()) {
$pager = $this->getLayout()->createBlock(
'Magento\Theme\Block\Html\Pager',
'name.pager'
)->setAvailableLimit(array(12=>12,24=>24,36=>36,72=>72))
->setShowPerPage(true)->setCollection(
$this->getYourFunction()
);
$this->setChild('pager', $pager);
$this->getTestimonials()->load();
}
return $this;
}
public function getPagerHtml()
{
return $this->getChildHtml('pager');
}
public function getYourFunction()
{
$page=($this->getRequest()->getParam('p'))? $this->getRequest()->getParam('p') : 1;
//get values of current limit
$pageSize=($this->getRequest()->getParam('limit'))? $this->getRequest
()->getParam('limit') : 12;
$collection = $this->yourFactory->create()->getCollection();
$collection->setPageSize($pageSize);
$collection->setCurPage($page)->getData();
return $collection;
}
}