function wpsc_pagination($totalpages = '', $per_page = '', $current_page = '', $page_link = '') { global $wp_query; $num_paged_links = 4; //amount of links to show on either side of current page $additional_links = ''; //additional links, items per page and products order if( get_option('permalink_structure') != '' ){ $additional_links_separator = '?'; }else{ $additional_links_separator = '&'; } if( !empty( $_GET['items_per_page'] ) ){ $additional_links = $additional_links_separator . 'items_per_page=' . $_GET['items_per_page']; $additional_links_separator = '&'; } if( !empty( $_GET['product_order'] ) ) $additional_links .= $additional_links_separator . 'product_order=' . $_GET['product_order']; $additional_links = apply_filters('wpsc_pagination_additional_links', $additional_links); //end of additional links if(empty($totalpages)){ $totalpages = $wp_query->max_num_pages; } if(empty($per_page)) $per_page = (int)get_option('wpsc_products_per_page'); $current_page = absint( get_query_var('paged') ); if($current_page == 0) $current_page = 1; if(empty($page_link)) $page_link = wpsc_a_page_url(); //if there is no pagination if(!get_option('permalink_structure')) { $category = '?'; if(isset($wp_query->query_vars['wpsc_product_category'])) $category = '?wpsc_product_category='.$wp_query->query_vars['wpsc_product_category']; if(isset($wp_query->query_vars['wpsc_product_category']) && is_string($wp_query->query_vars['wpsc_product_category'])){ $page_link = get_option('blogurl').$category.'&paged'; }else{ $page_link = get_option('product_list_url').$category.'&paged'; } $separator = '='; }else{ if ( isset( $wp_query->query_vars['wpsc_product_category'] ) ) { $category_id = get_term_by( 'slug', $wp_query->query_vars['wpsc_product_category'], 'wpsc_product_category' ); $page_link = trailingslashit( get_term_link( $category_id, 'wpsc_product_category' ) ); } else { $page_link = trailingslashit( get_option( 'product_list_url' ) ); } $separator = 'page/'; } // If there's only one page, return now and don't bother if($totalpages == 1) return; // Pagination Prefix $output = __('Pages: ','wpsc'); if(get_option('permalink_structure')){ // Should we show the FIRST PAGE link? if($current_page > 2) $output .= "" . __('« First', 'wpsc') . ""; // Should we show the PREVIOUS PAGE link? if($current_page > 1) { $previous_page = $current_page - 1; if( $previous_page == 1 ) $output .= " " . __('< Previous', 'wpsc') . " /"; else $output .= " " . __('< Previous', 'wpsc') . " /"; } $i =$current_page - $num_paged_links; $count = 1; if($i <= 0) $i =1; while($i < $current_page){ if($count <= $num_paged_links){ if($count == 1) $output .= "".$i.""; else $output .= " ".$i.""; } $i++; $count++; } // Current Page Number if($current_page > 0) $output .= "$current_page"; //Links after Current Page $i = $current_page + $num_paged_links; $count = 1; if($current_page < $totalpages){ while(($i) > $current_page){ if($count < $num_paged_links && ($count+$current_page) <= $totalpages){ $output .= " ".($count+$current_page).""; $i++; }else{ break; } $count ++; } } if($current_page < $totalpages) { $next_page = $current_page + 1; $output .= "/" . __('Next >', 'wpsc') . ""; } // Should we show the LAST PAGE link? if($current_page < $totalpages - 3) { $output .= "" . __('Last »', 'wpsc') . ""; } } else { // Should we show the FIRST PAGE link? if($current_page > 4) $output .= "" . __('« First', 'wpsc') . ""; // Should we show the PREVIOUS PAGE link? if($current_page > 1) { $previous_page = $current_page - 1; if( $previous_page == 1 ) $output .= " " . __('< Previous', 'wpsc') . ""; else $output .= " " . __('< Previous', 'wpsc') . ""; } $i =$current_page - $num_paged_links; $count = 1; if($i <= 0) $i =1; while($i < $current_page){ if($count <= $num_paged_links){ if($i == 1) $output .= " ".$i.""; else $output .= " ".$i.""; } $i++; $count++; } // Current Page Number if($current_page > 0) $output .= "$current_page"; //Links after Current Page $i = $current_page + $num_paged_links; $count = 1; if($current_page < $totalpages){ while(($i) > $current_page){ if($count < $num_paged_links && ($count+$current_page) <= $totalpages){ $output .= " ".($count+$current_page).""; $i++; }else{ break; } $count ++; } } if($current_page < $totalpages) { $next_page = $current_page + 1; $output .= "" . __('Next >', 'wpsc') . ""; } // Should we show the LAST PAGE link? if($current_page < $totalpages) { $output .= "" . __('Last »', 'wpsc') . ""; } } // Return the output. echo $output; }