我跟着这个链接,并创建了自己的自定义查询与分页..但我真的不明白是怎么偏移作品, https://wordpress.stackexchange.com/questions/21626/pagination-with-custom-sql-query分页不显示自定义查询(get_results)
分页无法正常工作。我得到零值的抵消。
function spiciest(){
global $wpdb, $paged, $max_num_pages;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_per_page = intval(get_query_var('posts_per_page')); //6
$offset = ($paged - 1)*$post_per_page;
/* Custom sql here. I left out the important bits and deleted the body
as it will be specific when you have your own. */
$sql = "
SELECT DISTINCT * FROM $wpdb->posts
INNER JOIN (SELECT *, SUBSTRING(name, 6) as 'post_ID',
votes_up AS votes_balance,
votes_up + votes_down AS votes_total
FROM thumbsup_items) AS thumbsup
ON $wpdb->posts.ID = thumbsup.post_ID
WHERE $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_password = ''
ORDER BY votes_up DESC, votes_balance DESC
LIMIT ".$offset.", ".$post_per_page."; ";
$sql_result = $wpdb->get_results($sql, OBJECT);
/* Determine the total of results found to calculate the max_num_pages
for next_posts_link navigation */
$sql_posts_total = $wpdb->get_var("SELECT FOUND_ROWS();");
$max_num_pages = ceil($sql_posts_total/$post_per_page);
print_r("offset ". $offset."\n") ;
print_r("\n"."sql_posts_total ". $sql_posts_total."\n") ;
print_r("\n"."max_num_pages ". $max_num_pages."\n") ;
return $sql_result;
}
请现场看看吧..我打印vlues .. http://goo.gl/fZTck 它应该有7页共39项。
已经试过了。没有运气。谢谢btw, – 2013-05-06 13:56:38