I want to show last number of page in pagination only.
The code of pagination comes from below path.
/var/www/html/magento/vendor/magento/module-theme/view/frontend/templates/html/pager.phtml
I'm using below code to get last category page.
<?php
$current_page = $this->getRequest()->getParam("p");
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');
$categoryId = $this->getrequest()->getParam(3); // YOUR CATEGORY ID
$category = $categoryFactory->create()->load($categoryId);
$productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addCategoryFilter($category);
$collection->setCurPage($current_page)->setPageSize(12);
echo $collection->getLastPageNumber();
?>
I could not get last page from this.