2012-12-03 14 views
0

我正在制作一个显示特定用户操作日志的插件。我的插件中的分页结果

问题是我需要添加分页来显示每页只有5个结果,而不是如何paginate_links()函数。

这是我的代码(有我需要添加分页)):

$mylink = $wpdb->get_results("SELECT * FROM wp_points"); 

foreach ($milink as $mostrar) 
{ 

<tr> 

echo"<td>".$mostrar->punto_user_ID."</td> 
<td>".$mostrar->punto_nombre."</td> 
<td>".number_format($mostrar->punto_canjeados, 0, ',', '.')."</td> 
<td>".cambiarFormatoFecha($mostrar->punto_fecha)."</td>"; 

} 
echo"</tr> 
</tbody> 
</table>"; 

请人谁可以使用代码帮助。

谢谢!

回答

1

这里有一个快速的解决方案,可以工作

功能使用

小区: http://php.net/manual/en/function.ceil.php

wpdb->准备 http://codex.wordpress.org/Class_Reference/wpdb

PAGINATE链接 http://codex.wordpress.org/Function_Reference/paginate_links

$per_page = 5; 
$page = intval(get_query_var('page')); // cast to int to be on the safe side 
$total_pages = ceil($wpdb->get_var("SELECT COUNT(*) FROM wp_points")/$per_page); 


//use $wpdb->prepare to help against sql injection 
$sql = $wpdb->prepare("SELECT * FROM wp_points LIMIT %d, %d", $page * $per_page, $per_page); 


// your processing here 

$mylink = $wpdb->get_results($sql); 
//... 

// here's the helper no magick here, straight from docs 
$big=999999999; // dummy used by 'base' below 

echo paginate_links(array(
    'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 
    'format' => '?page=%#%', 
    'current' => max(1, $page), 
    'total' => $total_pages, 
)); 
+0

谢谢!我为您提供了帮助,但现在我的代码出现了另一个问题。也许你可以帮助我,这是链接:[链接](http://stackoverflow.com/questions/13727000/i-can-not-paginate-my-plugin) –

+0

当你悬停在链接上,你看到?page = changing –

+0

编辑上述答案:在$ wp-> prepare引发($ page * $ per_page)中缺少$始终为零 –

0

最好看wp_query(“分页参数”是什么地方网页下半部) 使用类似:

$query = new WP_Query('posts_per_page=5');