Forums / General Questions / Product Listing [<< Prev] and [Next >>]

Product Listing [<< Prev] and [Next >>]

Views: 1,013

Results 1 to 5 of 5
29 Jan 2014, 9:13 PM
#1
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Product Listing [<< Prev] and [Next >>]

I searched for related threads but found NADA.

I am looking to have the [<< Prev] and [Next >>] appear all the time with a "inactive" class if say on page 1 and "inactive" class say on last page or "inactive" class if only 1 page.

Any suggestions?

29 Jan 2014, 9:51 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Product Listing [<< Prev] and [Next >>]

You could look at the "Products Pagination" plugin; it does what you're looking to do (and a little bit more).

29 Jan 2014, 10:01 PM
#3
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Product Listing [<< Prev] and [Next >>]

lat9:

You could look at the "Products Pagination" plugin; it does what you're looking to do (and a little bit more).

Not sure how I never saw that plugin, I will take a look! TY

29 Jan 2014, 10:42 PM
#4
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Product Listing [<< Prev] and [Next >>]

lat9:

You could look at the "Products Pagination" plugin; it does what you're looking to do (and a little bit more).

rbarbour:

Not sure how I never saw that plugin, I will take a look! TY

A little bit more merging (due to existing customized files) and adding of new files then I want for current project but I will consider for future ones. TY again!

30 Jan 2014, 1:00 AM
#5
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Product Listing [<< Prev] and [Next >>]

For anyone interested in simply styling the listing pages (product listing, new listing, all listing, featured listing, special listing and advanced search result listing) pagination links for a (RWD) Responsive Web Design.

Here is a copy of the CORE file /includes/classes/split_page_results.php

<?php
/**
 * split_page_results Class.
 *
 * @package classes
 * @copyright Copyright 2003-2012 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version GIT: $Id: Author: Ian Wilson  Fri Aug 17 17:54:58 2012 +0100 Modified in v1.5.1 $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
/**
 * Split Page Result Class
 *
 * An sql paging class, that allows for sql reslt to be shown over a number of pages using  simple navigation system
 * Overhaul scheduled for subsequent release
 *
 * @package classes
 */
class splitPageResults extends base {
  var $sql_query, $number_of_rows, $current_page_number, $number_of_pages, $number_of_rows_per_page, $page_name;

  /* class constructor */
  function splitPageResults($query, $max_rows, $count_key = '*', $page_holder = 'page', $debug = false, $countQuery = "") {
    global $db;
    $max_rows = ($max_rows == '' || $max_rows == 0) ? 20 : $max_rows;

    $this->sql_query = preg_replace("/\n\r|\r\n|\n|\r/", " ", $query);
    if ($countQuery != "") $countQuery = preg_replace("/\n\r|\r\n|\n|\r/", " ", $countQuery);
    $this->countQuery = ($countQuery != "") ? $countQuery : $this->sql_query;
    $this->page_name = $page_holder;

    if ($debug) {
      echo '<br /><br />';
      echo 'original_query=' . $query . '<br /><br />';
      echo 'original_count_query=' . $countQuery . '<br /><br />';
      echo 'sql_query=' . $this->sql_query . '<br /><br />';
      echo 'count_query=' . $this->countQuery . '<br /><br />';
    }
    if (isset($_GET[$page_holder])) {
      $page = $_GET[$page_holder];
    } elseif (isset($_POST[$page_holder])) {
      $page = $_POST[$page_holder];
    } else {
      $page = '';
    }

    if (empty($page) || !is_numeric($page)) $page = 1;
    $this->current_page_number = $page;

    $this->number_of_rows_per_page = $max_rows;

    $pos_to = strlen($this->countQuery);

    $query_lower = strtolower($this->countQuery);
    $pos_from = strpos($query_lower, ' from', 0);

    $pos_group_by = strpos($query_lower, ' group by', $pos_from);
    if (($pos_group_by < $pos_to) && ($pos_group_by != false)) $pos_to = $pos_group_by;

    $pos_having = strpos($query_lower, ' having', $pos_from);
    if (($pos_having < $pos_to) && ($pos_having != false)) $pos_to = $pos_having;

    $pos_order_by = strpos($query_lower, ' order by', $pos_from);
    if (($pos_order_by < $pos_to) && ($pos_order_by != false)) $pos_to = $pos_order_by;

    if (strpos($query_lower, 'distinct') || strpos($query_lower, 'group by')) {
      $count_string = 'distinct ' . zen_db_input($count_key);
    } else {
      $count_string = zen_db_input($count_key);
    }
    $count_query = "select count(" . $count_string . ") as total " . substr($this->countQuery, $pos_from, ($pos_to - $pos_from));
    if ($debug) {
      echo 'count_query=' . $count_query . '<br /><br />';
    }
    $count = $db->Execute($count_query);

    $this->number_of_rows = $count->fields['total'];

    $this->number_of_pages = ceil($this->number_of_rows / $this->number_of_rows_per_page);

    if ($this->current_page_number > $this->number_of_pages) {
      $this->current_page_number = $this->number_of_pages;
    }

    $offset = ($this->number_of_rows_per_page * ($this->current_page_number - 1));

    // fix offset error on some versions
    if ($offset <= 0) { $offset = 0; }

    $this->sql_query .= " limit " . ($offset > 0 ? $offset . ", " : '') . $this->number_of_rows_per_page;
  }

  /* class functions */

  // display split-page-number-links
  function display_links($max_page_links, $parameters = '') {
    global $request_type;
    if ($max_page_links == '') $max_page_links = 1;

    $display_links_string = '';

    $class = '';

    if (zen_not_null($parameters) && (substr($parameters, -1) != '&')) $parameters .= '&';

    // previous button - displayed but not clickable if first page
    if ($this->current_page_number == 1) $display_links_string .= '<span class="prev_link inactive">' . PREVNEXT_BUTTON_PREV . '</span>';


    // previous button - not displayed on first page
    if ($this->current_page_number > 1) $display_links_string .=  '<a href="' . zen_href_link($_GET['main_page'], $parameters . $this->page_name . '=' . ($this->current_page_number - 1), $request_type) . '" title=" ' . PREVNEXT_TITLE_PREVIOUS_PAGE . ' ">' . '<span class="prev_link active">' . PREVNEXT_BUTTON_PREV . '</span></a>';

    // check if number_of_pages > $max_page_links
    $cur_window_num = intval($this->current_page_number / $max_page_links);
    if ($this->current_page_number % $max_page_links) $cur_window_num++;

    $max_window_num = intval($this->number_of_pages / $max_page_links);
    if ($this->number_of_pages % $max_page_links) $max_window_num++;

    // previous window of pages
    if ($cur_window_num > 1) $display_links_string .= '<a href="' . zen_href_link($_GET['main_page'], $parameters . $this->page_name . '=' . (($cur_window_num - 1) * $max_page_links), $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE, $max_page_links) . ' "><span class="prev_set_links active">' . '...</span></a>';

    // page nn button
    for ($jump_to_page = 1 + (($cur_window_num - 1) * $max_page_links); ($jump_to_page <= ($cur_window_num * $max_page_links)) && ($jump_to_page <= $this->number_of_pages); $jump_to_page++) {
      if ($jump_to_page == $this->current_page_number) {
        $display_links_string .= '<span class="prev_next_page active">' . $jump_to_page . '</span>';
      } else {
        $display_links_string .= '<a href="' . zen_href_link($_GET['main_page'], $parameters . $this->page_name . '=' . $jump_to_page, $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_PAGE_NO, $jump_to_page) . ' ">' . '<span class="prev_next_page inactive">' . $jump_to_page . '</span></a>';
      }
    }

    // next window of pages
    if ($cur_window_num < $max_window_num) $display_links_string .= '<a href="' . zen_href_link($_GET['main_page'], $parameters . $this->page_name . '=' . (($cur_window_num) * $max_page_links + 1), $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links) . ' "><span class="next_set_links active">' . '...</span></a>';

    // next button - displayed but not clickable if last page
    if (($this->current_page_number == $this->number_of_pages) && ($this->number_of_pages != '')) $display_links_string .= '<span class="next_link inactive">' . PREVNEXT_BUTTON_NEXT . '</a></span>';

    // next button
    if (($this->current_page_number < $this->number_of_pages) && ($this->number_of_pages != 1)) $display_links_string .= '<a href="' . zen_href_link($_GET['main_page'], $parameters . 'page=' . ($this->current_page_number + 1), $request_type) . '" title=" ' . PREVNEXT_TITLE_NEXT_PAGE . ' "><span class="next_link active">' . PREVNEXT_BUTTON_NEXT . '</span></a>';

    if ($display_links_string == ' <strong class="current">1</strong> ') {
      return ' ';
    } else {
      return $display_links_string;
    }
  }

  // display number of total products found
  function display_count($text_output) {
    $to_num = ($this->number_of_rows_per_page * $this->current_page_number);
    if ($to_num > $this->number_of_rows) $to_num = $this->number_of_rows;

    $from_num = ($this->number_of_rows_per_page * ($this->current_page_number - 1));

    if ($to_num == 0) {
      $from_num = 0;
    } else {
      $from_num++;
    }

    if ($to_num <= 1) {
      // don't show count when 1
      return '';
    } else {
      return sprintf($text_output, $from_num, $to_num, $this->number_of_rows);
    }
  }
}

Using the stock admin > configuration > Maximum Values > Prev/Next Navigation Page Links set to 5

I added this to stylesheet.css

div#productsListingListingTopLinks, 
div#productsListingListingBottomLinks,
div#specialsListingTopLinks,
div#specialsListingBottomLinks,
div#newProductsDefaultListingTopLinks,
div#newProductsDefaultListingBottomLinks,
div#featuredProductsListingTopLinks,
div#featuredProductsListingBottomLinks,
div#allProductsListingTopLinks,
div#allProductsListingBottomLinks
{
 text-align:center;
 width:100%;
}

span.prev_link
{
-webkit-border-top-left-radius: 6px;
-webkit-border-bottom-left-radius: 6px;
-moz-border-radius-topleft: 6px;
-moz-border-radius-bottomleft: 6px;
border-top-left-radius: 6px;
border-bottom-left-radius: 6px;
}

span.next_link
{
-webkit-border-top-right-radius: 6px;
-webkit-border-bottom-right-radius: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-bottomright: 6px;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
}

span.prev_link,
span.prev_set_links,
span.prev_next_page,
span.next_set_links,
span.next_link
{
  width:12.5%;
  line-height:30px;
  display:inline-block;
  background:#E6E6E6;
  font-size:14px;
  color:#505050;
}

span.prev_link a,
span.prev_set_links a,
span.prev_next_page a,
span.next_set_links a,
span.next_link a
{
  color:#505050;
}

span.prev_link.active:hover,
span.prev_link.active:hover a,
span.prev_set_links.active:hover,
span.prev_set_links.active:hover a,
span.prev_next_page.active,
span.prev_next_page.inactive:hover,
span.prev_next_page.inactive:hover a,
span.next_set_links.active:hover,
span.next_set_links.active:hover a,
span.next_link.active:hover,
span.next_link.active:hover a
{
  background:#2BA6C6;
  color:#FFFFFF;
}

The above was done to add a Responsive pagination to the listing pages simply by overriding 1 file and adding CSS.

If looking for the same as above with an option for pagination via drop-down I would suggest the plugin by lat9 that lat9 suggested.