Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Adding pagination to Product page
 
wdebruin
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-07-09
 

Usibility wise I think it would be great to allow the user to page back and forward through the products in the order they displayed on the product list page/category page (sort by order as well).

I gave it a go and came up with the following solution - would appreciate it if anyone could better the code:

In the list template I created a session variable that holds all the product url’s of the products listed:
.../templates/catalog/product/list.phtml after the 1st else statement around line #36

<?php 
    
    $prodPgNavArr 
= array();
    
$i=0; foreach ($_productCollection as $_product
    
        $prodPgNavArr[$i] 
$_product->getProductUrl();  
        
$i++;
        
    
}
    
    
// put the array in a session variable
    
$_SESSION['prodPgNav']=$prodPgNavArr;

?>

and retrieve these on the product page and conditionally display ‘previous’ and ‘next’ links:
.../templates/catalog/product/view/media.phtml at the top:

<?php

    
// get current product URl
    
$currentPath "http://" $_SERVER['HTTP_HOST'$_SERVER['REQUEST_URI'];
     
    
//
    
$prodPgNavArr $_SESSION['prodPgNav'];
    
    
// loop through the session array to find index of current product in product list/array
    
foreach($prodPgNavArr as $key=>$value{
    
        
if($currentPath == $value{
            $prevIndex 
$key 1;            
            
$nextIndex $key 1;
        
}    
    }
       
if (isset($prevIndex) && $prevIndex!=-1{
        
echo "<div>&#8220;&nbsp;<a href='$prodPgNavArr[$prevIndex]'>previous</a></div>";
    
}
    
if (isset($nextIndex) && $nextIndex<sizeof($prodPgNavArr)) {
        
echo "<div>&#8221;&nbsp;<a href='$prodPgNavArr[$nextIndex]'>next</a></div>";
    
}
?>

Okay this works, but only lists the first 8 products from my product listing page, because that’s what I set my listing limit per page at. Instead I would appreciate advice on how to retrieve ALL the products in the listing. 

I hope this makes sense. If there’s a better (object orientated) way of solving this, please let me know.

 
Magento Community Magento Community
Magento Community
Magento Community
 
fenixf
Member
 
Total Posts:  35
Joined:  2008-04-08
 

You must change the show items per page in admin->configuration->catalog to “all” or a high number.
Then will get all the products in that category.

 
Magento Community Magento Community
Magento Community
Magento Community
 
wdebruin
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-07-09
 

I probably didn’t make that clear ... this is where I butt heads with my designer partner - who only wants a max of 8 items to show per page.

Is there a way I could replicate the load of All products (not the whole page - just loop through and grab their urls) in an include on the list page and thus have all the url’s store in the session variable?

Help please!

 
Magento Community Magento Community
Magento Community
Magento Community
 
trrill
Jr. Member
 
Total Posts:  3
Joined:  2008-08-28
 

I’m up against this very problem. This thread’s been inactive for a while, and I’m wondering if you ever figured out a solution to it. I’m sort of wanting to do two things:

1) Paginate “Next product” and “Previous” product based on the list view.
2) Display thumbnails from the Product’s deepest category/collection.

You can see my progress (and stagnation) with #2 at:
http://www.magentocommerce.com/boards/viewthread/19090/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top