2

I would like to use pagination by text box where client can type the number of product page and click go/submit button.

1
<?php  $totalpage=$collection->getLastPageNumber(); //get total number of pages
$currentUrl = Mage::helper('core/url')->getCurrentUrl();

 ?>
<input type="text" name="pager" id="pager"> <input type="button" value="go" onClick="gopage()">

<script>
function gopage()
{
  vale=$('pager').getValue();
  if(vale >=<?php echo totalpage; ?>) {
  window.location='<?php echo currentUrl ?>?page'+vale;
   }
}
</script>
1

you must insert the code below in

\app\design\frontend\YOURTEMPLATE\default\template\page\html\pager.phtml

or

\app\design\frontend\YOURTEMPLATE\default\template\catalog\product\list\toolbar.phtml
0
<?php  $totalpage=$_productCollection->getLastPageNumber(); //get total number of pages
        echo "Total Page is " . $totalpage;
        $currentUrl = Mage::helper('core/url')->getCurrentUrl();
        //echo $currentUrl;
         ?>
            | Enter Page Number: <input type="text" name="pager" id="pager"> <input type="button" value="Go To Page" onClick="gopage()">

        <script>
        function gopage()
        {
            var x = '<?php echo $currentUrl; ?>';
            //alert(x);
            var url = x.split('?')[0];
            //alert(url);

         vale=document.getElementById("pager").value;
          //alert(vale);

          if(isNaN(vale)==true || Number(vale) >'<?php echo $totalpage; ?>') {
                alert('Your maximun page number is ' + '<?php echo $totalpage; ?>');

           }
           else{
                window.location=url+'?p='+vale;     
           }    
        }
        </script>
  • Please add some explanation: what does the code do, where do you add it? Code-only answers are not very helpful. – Fabian Schmengler Jan 19 '16 at 8:10

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.