Most popular ads are not properly paginated
Hello, I want to pay the attention of developers.
The 'Most popular' ads are not properly paginated!
I found a bug in the file 'loop-featured.php'.
Take a look at the code:
PHP Code:
$start = $paged * 10;
// Add an additional entry to test for a next page
$end = $start + 10 + 1;
// give us the most popular ads based on page views
$sql = $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "cp_ad_pop_total a "
. "INNER JOIN " . $wpdb->posts . " p ON p.ID = a.postnum "
. "WHERE postcount > 0 AND post_status = 'publish' AND post_type = '".APP_POST_TYPE."' "
. "ORDER BY postcount DESC LIMIT $start,$end" );
$pageposts = $wpdb->get_results( $sql );
global $cp_has_next_page;
if(count($pageposts) == 11){
$cp_has_next_page = true;
}else{
$cp_has_next_page = false;
}
$pageposts = array_slice( $pageposts, 0, 10);
On the home page variable $paged = 0:
$start = $paged * 10 = 0
$end = $start + 10 + 1 = 11
And we see a records from 0 to 10
Click on the link 'view more ads' and go to the page 2:
$paged = 2
$start = $paged * 10 = 20
$end = $start + 10 + 1 = 31
And we see a records from 21 to 30
Where records from 11 to 20?
That's how I fixed it:
PHP Code:
if ( $paged != 0 ) $var = 10;
$start = $paged * 10 - $var;
// Add an additional entry to test for a next page
$end = $start + 10 + 1;
// give us the most popular ads based on page views
$sql = $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "cp_ad_pop_total a "
. "INNER JOIN " . $wpdb->posts . " p ON p.ID = a.postnum "
. "WHERE postcount > 0 AND post_status = 'publish' AND post_type = '".APP_POST_TYPE."' "
. "ORDER BY postcount DESC LIMIT $start,$end" );
$pageposts = $wpdb->get_results( $sql );
global $cp_has_next_page;
if(count($pageposts) == 11){
$cp_has_next_page = true;
}else{
$cp_has_next_page = false;
}
$pageposts = array_slice( $pageposts, 0, 10);
Perhaps this is not a serious bug, but please fix it.
This is not a serious way!
By the way, why on the second page, there are no links to the next pages 3, 4, 5 ... ?
If you type in the browser '.../page/3/?Sort=popular' page will be opened correctly. Where are the links?
Thank you for your attention.