I want to show Title of category page based current page and total page. for example: Category Electronics has total 20 page and i am on 2nd page. I want to show 2 out of 20 pages.

I have tried below code.

 $current_page =  $this->request->getParam("p");

 $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
            $categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');

            $categoryId = $this->request->getParam("id"); // YOUR CATEGORY ID
            $category = $categoryFactory->create()->load($categoryId);

            $productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
            $collection = $productCollectionFactory->create();

            $collection->addAttributeToFilter('visibility', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);

echo $current_page." of "ceil(count($collection)/48);

I have limiter value 48. But i am getting different count of product than actual showing in category page.

  • Try to load the collection: $collection->load(); or $collection->count(). – Khoa TruongDinh Oct 22 '17 at 10:16

You need to set page limit and page number in collection. Try following way:

echo $current_page." of ".$collection->getLastPageNumber();

Following line return last page number. For example: you have 10 page then it return 10.

| improve this answer | |
  • @shoelrana I can use this thing but collection count is not correct I can see total product showing is 65 and getting collection of 190 products. – Kul Oct 23 '17 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.