WordPress.org

Ready to get started?Download WordPress

Forums

Help with pagination class php (wpsc) (5 posts)

  1. Omolly
    Member
    Posted 4 years ago #

    Some one please help me!!
    wp version:2.9.2
    wpsc version:3.7.6.1
    I can't get pagination to work on my wpsc for my product list even with pagination turned on in the setting panel and after deleting the content of the cache in the Wp_options table in the DB.
    I've been trawlling the web for a whole month now looking for a solution that works. I discovered there is a pagination.class.php file in the wpsc and I wonder if the answer may lie in the code. Unfortunately I don't know php at all so I'm weary of tampering with the file.

    Can someone please tell me what might work? Here is the php code as is:
    <?php

    /**
    * wpsc pagination
    * It is intended to move some of this functionality to a paging class
    * so that paging functionality can easily be created for multiple uses.
    */

    /**
    * wpsc current_page
    * @return (int) The current page number
    */
    function wpsc_current_page() {

    global $wpsc_query;

    $current_page = 1;

    if ( $wpsc_query->query_vars['page'] > 1) {
    $current_page = $wpsc_query->query_vars['page'];
    }

    return $current_page;

    }

    /**
    * wpsc showing products
    * Displays the number of page showing in the form "10 to 20".
    * If only on page is being display it will return the total amount of products showing.
    * @return (string) Number of products showing
    */
    function wpsc_showing_products() {

    global $wpsc_query;

    // If we are using pages...
    if ( ( get_option( 'use_pagination' ) == 1 ) ) {
    $products_per_page = $wpsc_query->query_vars['number_per_page'];
    if ( $wpsc_query->query_vars['page'] > 0 ) {
    $startnum = ( $wpsc_query->query_vars['page'] - 1 ) * $products_per_page;
    } else {
    $startnum = 0;
    }
    return ( $startnum + 1 ) . ' to ' . ( $startnum + wpsc_product_count() );
    }

    return wpsc_total_product_count();

    }

    /**
    * wpsc showing products page
    * Displays the number of page showing in the form "5 of 10".
    * @return (string) Number of pages showing.
    */
    function wpsc_showing_products_page() {

    global $wpsc_query;

    $output = $wpsc_query->page_count;
    $current_page = wpsc_current_page();

    return $current_page . ' of ' . $output;

    }

    /**
    * wpsc pagination
    * Page numbers as links - limit by passing the $show parameter.
    * @param $show (int) Number of pages to show, -1 shows all. Zero will be used to show default setting in a future release.
    * @return (string) Linked page numbers.
    */
    function wpsc_pagination( $show = -1 ) {

    global $wpsc_query;

    $output = '';
    $start = 1;
    $end = $wpsc_query->page_count;
    $show = intval( $show );

    $current_page = wpsc_current_page();

    if ( $show > 0 ) {
    $start = $current_page - ( floor( $show / 2 ) );
    if ( $start < 1 ) {
    $start = 1;
    }
    $end = $start + $show - 1;
    if ( $end > $wpsc_query->page_count ) {
    $end = $wpsc_query->page_count;
    if ( $end - $show + 1 > 0 ) {
    $start = $end - $show + 1;
    }
    }
    }
    while ( wpsc_have_pages() ) : wpsc_the_page();
    if ( wpsc_page_number() >= $start && wpsc_page_number() <= $end ) {
    if ( wpsc_page_is_selected() ) :
    $output .= '' . wpsc_page_number() . ' ';
    else :
    $output .= '' . wpsc_page_number() . ' ';
    endif;
    }
    endwhile;

    $wpsc_query->rewind_pages();

    return $output;

    }

    /**
    * wpsc adjacent products url
    * URL for the next or previous page of products on a category or group page.
    * @param $n (int) Page number.
    * @return (string) URL for the adjacent products page link.
    */
    function wpsc_adjacent_products_url( $n ) {

    global $wpsc_query;

    $current_page = wpsc_current_page();

    $n = $current_page + $n;

    if ( $n < 1 || $n > $wpsc_query->page_count ) {
    return;
    }

    while ( wpsc_have_pages() ) : wpsc_the_page();
    if ( wpsc_page_number() == $n ) {
    $url = wpsc_page_url();
    $wpsc_query->rewind_pages();
    return $url;
    }
    endwhile;

    $wpsc_query->rewind_pages();

    return;

    }

    /**
    * wpsc next products link
    * Links to the next page of products on a category or group page.
    * @param $text (string) Link text.
    * @param $show_disabled (bool) Show unlinked text if last page.
    * @return (string) Next page link or text.
    */
    function wpsc_next_products_link( $text = 'Next', $show_disabled = false) {

    $page_url = wpsc_adjacent_products_url( 1 );

    if ( $page_url ) {
    return '' . $text . '';
    }

    if ( $show_disabled ) {
    return '<span>' . $text . '</span>';
    }

    return;

    }

    /**
    * wpsc previous products link
    * Links to the previous page of products on a category or group page.
    * @param $text (string) Link text.
    * @param $show_disabled (bool) Show unlinked text if first page.
    * @return (string) Previous page link or text.
    */
    function wpsc_previous_products_link( $text = 'Previous', $show_disabled = false ) {

    $page_url = wpsc_adjacent_products_url( -1 );

    if ( $page_url ) {
    return '' . $text . '';
    }

    if ( $show_disabled ) {
    return '<span>' . $text . '</span>';
    }

    return;

    }

    /**
    * wpsc first products link
    * Links to the first page of products on a category or group page.
    * @param $text (string) Link text.
    * @param $show_disabled (bool) Show unlinked text if last page.
    * @return (string) First page link or text.
    */
    function wpsc_first_products_link( $text = 'First', $show_disabled = false ) {

    global $wpsc_query;

    $page_url = '';

    while ( wpsc_have_pages() ) : wpsc_the_page();
    $page_url = wpsc_page_url();
    break;
    endwhile;

    $wpsc_query->rewind_pages();

    if ( $page_url && wpsc_current_page() > 1 ) {
    return '' . $text . '';
    }

    if ( $show_disabled ) {
    return '<span>' . $text . '</span>';
    }

    return;

    }

    /**
    * wpsc last products link
    * Links to the last page of products on a category or group page.
    * @param $text (string) Link text.
    * @param $show_disabled (bool) Show unlinked text if first page.
    * @return (string) Last page link or text.
    */
    function wpsc_last_products_link( $text = 'Last', $show_disabled = false ) {

    global $wpsc_query;

    $page_url = '';

    while ( wpsc_have_pages() ) : wpsc_the_page();
    $page_url = wpsc_page_url();
    endwhile;

    $wpsc_query->rewind_pages();

    if ( $page_url && wpsc_current_page() < $wpsc_query->page_count ) {
    return '' . $text . '';
    }

    if ( $show_disabled ) {
    return '<span>' . $text . '</span>';
    }

    return;

    }

    ?>

  2. Darrell Schauss
    Member
    Posted 4 years ago #

    Does your products_page.php theme file for WPSC have the pagination code in it?

    The one from the default theme starts with
    <?php if(wpsc_has_pages() && ((get_option('wpsc_page_number_position') == 1 ) || (get_option('wpsc_page_number_position') == 3))) : ?>

  3. Omolly
    Member
    Posted 4 years ago #

    Hi dralezero,
    Thanks for replying to my post.
    I'm using the default theme and it does have the products_page.php file. The code starts with:
    #
    <?php
    #
    global $wpsc_query, $wpdb;
    #
    /*
    #
    * Most functions called in this page can be found in the wpsc_query.php file
    #
    */
    #
    ?>
    #
    <div id='products_page_container' class="wrap wpsc_container">
    #

    #
    <?php if(wpsc_has_breadcrumbs()) : ?>
    #
    <div class='breadcrumb'>
    #
    '><?php echo get_option('blogname'); ?> »
    #
    <?php while (wpsc_have_breadcrumbs()) : wpsc_the_breadcrumb(); ?>
    #
    <?php if(wpsc_breadcrumb_url()) :?>
    #
    '><?php echo wpsc_breadcrumb_name(); ?> »
    #
    <?php else: ?>
    #

    It's a bit different from the one you've posted here. Do I need it in my chosen theme then?

  4. Darrell Schauss
    Member
    Posted 4 years ago #

    Everything from <?php if(wpsc_has_pages() to the endif; on that IF block of code (it should only be a few lines) should be in your template for display the numbers.

    This is how it looks in WPSC 3.7.6.1 so you know what to sort of look for.

    <!-- Start Pagination -->
    		<?php if ( ( get_option( 'use_pagination' ) == 1 && ( get_option( 'wpsc_page_number_position' ) == 1 || get_option( 'wpsc_page_number_position' ) == 3 ) ) ) : ?>
    			<div class="wpsc_page_numbers">
    				<?php if ( wpsc_has_pages() ) : ?>
    					Pages: <?php echo wpsc_first_products_link( '&laquo; First', true ); ?> <?php echo wpsc_previous_products_link( '&laquo; Previous', true ); ?> <?php echo wpsc_pagination( 10 ); ?> <?php echo wpsc_next_products_link( 'Next &raquo;', true ); ?> <?php echo wpsc_last_products_link( 'Last &raquo;', true ); ?>
    				<?php endif; ?>
    			</div>
    		<?php endif; ?>
    		<!-- End Pagination -->

    Also for posting large blocks of code like the full template page, etc use http://pastebin.com/
    For short blocks like I just did use the CODE button that makes the small tick marks.

  5. Omolly
    Member
    Posted 4 years ago #

    Hi dralezero,
    I've looked in the product_page.php file for the default wpsc theme and the 'start pagination' code (starting from line 69 in version 3.7.6.1) looks it like the below:

    <!-- Start Pagination -->
    <?php if ( ( get_option( 'use_pagination' ) == 1 && ( get_option( 'wpsc_page_number_position' ) == 1 || get_option( 'wpsc_page_number_position' ) == 3 ) ) ) : ?>
    <div class="wpsc_page_numbers">
    <?php if ( wpsc_has_pages() ) : ?>
    Pages: <?php echo wpsc_first_products_link( '&laquo; First', true ); ?> <?php echo wpsc_previous_products_link( '&laquo; Previous', true ); ?> <?php echo wpsc_pagination( 10 ); ?> <?php echo wpsc_next_products_link( 'Next &raquo;', true ); ?> <?php echo wpsc_last_products_link( 'Last &raquo;', true ); ?>
    <?php endif; ?>
    </div>
    <?php endif; ?>
    <!-- End Pagination -->

Topic Closed

This topic has been closed to new replies.

About this Topic