2013-02-24 101 views
1

在WordPress中开发一个插件,并且很好,但是插件页面的分页卡住了。下面是从互联网下载我的代码(有从这里参考)WordPress:在插件设置页面分页时遇到问题

$items = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->review_media GROUP BY post_id")); // number of total rows in the database 

//测试,并得到了结果评价 的print_r($项目); //说这是输出值2 echo $ rm_options ['list_per_page']; //这是我的选择设定值1

if($items > 0) { 
     $p = new pagination; 
     $p->items($items); 
     $p->limit(empty($rm_options['list_per_page']) ? 20 : $rm_options['list_per_page']); // Limit entries per page 
     $p->target("admin.php?page=moderate.php"); 
     $p->currentPage($_GET[$p->paging]); // Gets and validates the current page 
     $p->calculate(); // Calculates what to show 
     $p->parameterName('paging'); 
     $p->adjacents(1); //No. of page away from the current page 

     if(!isset($_GET['paging'])) { 
      $p->page = 1; 
     } else { 
      $p->page = $_GET['paging']; 
     } 

     //Query for limit paging 
     $limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit; 

} else { 
    echo "No Record Found"; 
} 

当我通过POST_ID不组我的查询它工作正常,但只要我的分组行为怪异。它创建一个分页链接并获得空白页面。我认为原因在于将该行分组。但不知道如何解决这个问题。

这里是我的表截图

enter image description here

非常感谢您的帮助...

+0

我不知道类,它不在你的问题,但我认为这里有一个错误:'$ p-> currentPage($ _GET [$ p-> paging])''。我想它应该是'$ p-> currentPage($ _GET ['paging'])' – 2013-02-24 10:32:55

+0

没有它的不工作。班级,你可以在这里找到http://mis-algoritmos.com/2007/05/27/digg-style-pagination-class – 2013-02-24 10:36:28

回答

0

如果你使用WordPress WP_List_Table类,很会照顾的分页,并提供一个缺省的表用户体验。

tutorial涵盖了这一切,分页部分是:本教学中

function prepare_items() { 
    [...] 
    $per_page = 5; 
    $current_page = $this->get_pagenum(); 
    $total_items = count($this->example_data); 

    // only necessary because we have sample data 
    $this->found_data = array_slice($this->example_data,(($current_page-1)*$per_page),$per_page); 

    $this->set_pagination_args(array(
    'total_items' => $total_items, //WE have to calculate the total number of items 
    'per_page' => $per_page  //WE have to determine how many items to show on a page 
)); 
    $this->items = $this->found_data; 
} 

而且here's the full plugin。在other plugin中,您可以看到WP_List_Table正在使用数据库数据。