Finished pagination on the frontend

This commit is contained in:
Will Bradley 2014-02-26 16:36:05 -07:00
parent 980437bc9c
commit 9d6ac396b3
4 changed files with 58 additions and 6 deletions

View File

@ -1086,16 +1086,26 @@ if ( !class_exists( 'Simple_Map' ) ) {
var results = document.getElementById('results');
results.innerHTML = '';
// parse JSON from server
var jsonData = jQuery( eval(data) )[0];
var total_pages = jsonData.total_pages;
var this_page = jsonData.this_page;
// Create page links
page_links = "";
for(i=1;i<=5;i++){
page_links += '<a href="?location_search_page='+i+'">'+i+'</a> ';
for(i=1;i<=total_pages;i++){
page_links += '<a href="?location_search_page='+i+'"';
if(i == this_page){
page_links += ' class="active"';
}
page_links += '>'+i+'</a> ';
}
jQuery( "#pagination" ).html( page_links );
// Create markers
var markers = jQuery( jsonData.locations );
var markers = jQuery( eval( data ) );
if (markers.length == 0) {
results.innerHTML = '<h3>' + noresults_text + '</h3>';
map.setCenter( searchData.center );

View File

@ -43,10 +43,13 @@ if ( !class_exists( 'SM_XML_Search' ) ){
$distance_select = $distance_having = $distance_order = '';
// We're going to do a hard limit to 5000 for now.
if ( !$input['limit'] || $input['limit'] > 250 )
if ( !$input['limit'] || $input['limit'] > 250 || $input['limit'] == 0 ) {
$limit_int = 250;
$limit = "LIMIT 250";
}
else
$limit = 'LIMIT ' . absint( $input['limit'] );
$limit_int = absint( $input['limit'] );
$limit = 'LIMIT ' . $limit_int;
$limit = apply_filters( 'sm-xml-search-limit', $limit );
@ -96,6 +99,26 @@ if ( !class_exists( 'SM_XML_Search' ) ){
$i++;
}
}
// Find out how many items are in the table
$total_locations_sql = $wpdb->get_var( "
SELECT
COUNT(*)
FROM
$wpdb->posts AS posts
INNER JOIN
$wpdb->postmeta lat_tbl ON lat_tbl.post_id = posts.ID AND lat_tbl.meta_key = 'location_lat'
INNER JOIN
$wpdb->postmeta lng_tbl ON lng_tbl.post_id = posts.ID AND lng_tbl.meta_key = 'location_lng'
$taxonomy_join
WHERE
posts.post_type = 'sm-location'
AND posts.post_status = 'publish'
" );
$total_locations = absint($total_locations_sql);
$total_pages = ceil($total_locations / $limit_int); // use ceiling to round up -- 0.01 is still "1 page"
$this_page_number = absint($input['page']);
$sql = "SELECT
lat_tbl.meta_value AS lat,
@ -188,7 +211,8 @@ if ( !class_exists( 'SM_XML_Search' ) ){
}
$locations = apply_filters( 'sm-xml-search-locations', $locations );
$this->print_json( $locations, $smtaxes );
$output = array('locations' => $locations, 'total_locations' => $total_locations, 'total_pages' => $total_pages, 'this_page' => $this_page_number);
$this->print_json( $output, $smtaxes );
}
}

View File

@ -188,6 +188,15 @@ font-style: italic;
background: url( ../images/star.png ) no-repeat left center;
}
div#pagination a {
text-decoration: underline;
}
div#pagination a.active {
text-decoration: none;
color: #000;
}
.location_search_title, .location_search_distance_cell, .location_search_taxonomy_cell {
font-weight:bold;
vertical-align:top;

View File

@ -188,6 +188,15 @@ font-style: italic;
background: url( ../images/star.png ) no-repeat left center;
}
div#pagination a {
text-decoration: underline;
}
div#pagination a.active {
text-decoration: none;
color: #000;
}
.location_search_title, .location_search_distance_cell, .location_search_taxonomy_cell {
font-weight:bold;
vertical-align:top;