Finished pagination on the frontend
This commit is contained in:
parent
980437bc9c
commit
9d6ac396b3
|
@ -1086,16 +1086,26 @@ if ( !class_exists( 'Simple_Map' ) ) {
|
||||||
var results = document.getElementById('results');
|
var results = document.getElementById('results');
|
||||||
results.innerHTML = '';
|
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
|
// Create page links
|
||||||
page_links = "";
|
page_links = "";
|
||||||
for(i=1;i<=5;i++){
|
for(i=1;i<=total_pages;i++){
|
||||||
page_links += '<a href="?location_search_page='+i+'">'+i+'</a> ';
|
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 );
|
jQuery( "#pagination" ).html( page_links );
|
||||||
|
|
||||||
|
// Create markers
|
||||||
|
var markers = jQuery( jsonData.locations );
|
||||||
|
|
||||||
var markers = jQuery( eval( data ) );
|
|
||||||
if (markers.length == 0) {
|
if (markers.length == 0) {
|
||||||
results.innerHTML = '<h3>' + noresults_text + '</h3>';
|
results.innerHTML = '<h3>' + noresults_text + '</h3>';
|
||||||
map.setCenter( searchData.center );
|
map.setCenter( searchData.center );
|
||||||
|
|
|
@ -43,10 +43,13 @@ if ( !class_exists( 'SM_XML_Search' ) ){
|
||||||
$distance_select = $distance_having = $distance_order = '';
|
$distance_select = $distance_having = $distance_order = '';
|
||||||
|
|
||||||
// We're going to do a hard limit to 5000 for now.
|
// 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";
|
$limit = "LIMIT 250";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
$limit = 'LIMIT ' . absint( $input['limit'] );
|
$limit_int = absint( $input['limit'] );
|
||||||
|
$limit = 'LIMIT ' . $limit_int;
|
||||||
|
|
||||||
$limit = apply_filters( 'sm-xml-search-limit', $limit );
|
$limit = apply_filters( 'sm-xml-search-limit', $limit );
|
||||||
|
|
||||||
|
@ -96,6 +99,26 @@ if ( !class_exists( 'SM_XML_Search' ) ){
|
||||||
$i++;
|
$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
|
$sql = "SELECT
|
||||||
lat_tbl.meta_value AS lat,
|
lat_tbl.meta_value AS lat,
|
||||||
|
@ -188,7 +211,8 @@ if ( !class_exists( 'SM_XML_Search' ) ){
|
||||||
}
|
}
|
||||||
|
|
||||||
$locations = apply_filters( 'sm-xml-search-locations', $locations );
|
$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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,15 @@ font-style: italic;
|
||||||
background: url( ../images/star.png ) no-repeat left center;
|
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 {
|
.location_search_title, .location_search_distance_cell, .location_search_taxonomy_cell {
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
vertical-align:top;
|
vertical-align:top;
|
||||||
|
|
|
@ -188,6 +188,15 @@ font-style: italic;
|
||||||
background: url( ../images/star.png ) no-repeat left center;
|
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 {
|
.location_search_title, .location_search_distance_cell, .location_search_taxonomy_cell {
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
vertical-align:top;
|
vertical-align:top;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user