php - Magento - Adding page number to title on products listing -
i have extension uses products list block show products grid filter attribute (the extension attribute info pages).
in "_preparelayout" function of extension block extension sets page's title , description using code :
$head = $this->getlayout()->getblock('head'); . . . $head->settitle($title); head->setdescription($des);
i want add text title , description in format :
$page_info = "page of b "; $title = $page_info . title; $items_info = "listings x-y (out of z) "; $des = items_info . $des;
i've tried code order current page, last page, number , items , on :
$html_pager = mage::getblocksingleton('page/html_pager'); $html_pager->setcollection($product_collection); $limit = mage::getsingleton('core/app')->getrequest()->getparam('limit'); if(empty($limit)) { $limit = 8; } $html_pager->setlimit($limit); $lastpagenumber = $html_pager->getlastpagenum(); $current_page = $html_pager->getcurrentpage(); $page_info = ""; if($current_page > 1) { $page_info = "page " . $current_page . " of $lastpagenumber "; } $firstnum = $html_pager->getfirstnum(); $lastnum = $html_pager->getlastnum(); $totalnum = $html_pager->gettotalnum(); $items_info = "listings " . $firstnum . "-" . $lastnum . " (out of ". $totalnum . ") ";
the code gives me correct information causes problem in products grid - shows 10 products in products grid (no matter choose in "show per page").
any ideas how information without breaking grid functionality?
i found solution works me:
$product_collection = clone mage::getsingleton('catalog/layer')->getproductcollection(); $total = count($product_collection); $current_page = mage::getblocksingleton('page/html_pager')->getcurrentpage(); $limit = mage::getsingleton('core/app')->getrequest()->getparam('limit'); if(empty($limit)) { $limit = mage::getstoreconfig('catalog/frontend/grid_per_page'); } $pages = $total / $limit; $pages = ceil($pages); if($current_page > 1) { $page_info = "page " . $current_page . " of $pages "; } $firstnum = $limit*($current_page-1)+1; if($current_page == $pages) { $lastnum = $total; } else { $lastnum = $limit + ($firstnum - 1); } $items_info = "listings " . $firstnum . "-" . $lastnum . " (out of ". $total . ") ";
Comments
Post a Comment