diff --git a/classes/simplemap.php b/classes/simplemap.php
index 61695d9..572e62b 100755
--- a/classes/simplemap.php
+++ b/classes/simplemap.php
@@ -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 += ''+i+' ';
+ for(i=1;i<=total_pages;i++){
+ page_links += ''+i+' ';
}
jQuery( "#pagination" ).html( page_links );
+ // Create markers
+ var markers = jQuery( jsonData.locations );
- var markers = jQuery( eval( data ) );
if (markers.length == 0) {
results.innerHTML = '
' + noresults_text + '
';
map.setCenter( searchData.center );
diff --git a/classes/xml-search.php b/classes/xml-search.php
index 67a4bce..727dea9 100755
--- a/classes/xml-search.php
+++ b/classes/xml-search.php
@@ -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 );
}
}
diff --git a/inc/styles/dark.css b/inc/styles/dark.css
index a22faa4..84be4a2 100755
--- a/inc/styles/dark.css
+++ b/inc/styles/dark.css
@@ -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;
diff --git a/inc/styles/light.css b/inc/styles/light.css
index b5313b8..298600c 100755
--- a/inc/styles/light.css
+++ b/inc/styles/light.css
@@ -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;