[英]Error in entries per page count
我正在一个有分页条目并希望输出当前位置的网站,例如, Showing 10-18 of 50 results
但是如果条目数少于每页限制,则很难获得正确的输出。
该站点使用ExpressionEngine,其中URI的最后一段指示您在页面列表中的位置,因此,如果限制为每页9,则当您位于第二页时,URI将为/path/to/page/P9/
, P18
第3页等。
这是我到目前为止的内容:
$output = '';
// the variables below are passed from a template to a plugin which does the processing
$url_segment = $this->EE->TMPL->fetch_param('url_segment'); // e.g. P9, P18 etc.
$per_page = $this->EE->TMPL->fetch_param('page_num'); // e.g. 9
$total_entries = $this->EE->TMPL->fetch_param('total'); // e.g. 50
$current_page = preg_match('/^P+[0-9]+$/', $url_segment) === 1 ? str_replace('P','', $url_segment) +1 : 1;
if ($total_entries == 1) {
$output .= '1 tour';
} else {
if ($total_entries <= $per_page){
$output .= '1 to '.($per_page<=$total_entries ? $total_entries : $per_page);
} else {
$output .= $current_page.' to ';
$output .= $current_page+$per_page-1;
}
$output .= ' of '.$total_entries.' tours';
}
return $this->return_data = $output;
if ($total_entries <= $per_page)
似乎从未评估为true,例如,如果页面限制为9,但只有三个条目,它将说1 to 9 of 3 entries
。
我认为这可能是因为我需要使变量为整数,但这意味着条件的另一端始终求值为true,因此,当有更多条目超出每页限制时,无论您在哪一页上输出,输出始终是相同的例如在所有页面上1 to 14 of 14 entries
。
我要去哪里错了?
if ($total_entries <= $per_page){
$output .= '1 to '.($per_page<=$total_entries ? $total_entries : $per_page);
在这一部分,您首先要检查$total_entries
是否小于或等于$per_page
,但是$per_page
,您要检查它是否大于或等于$per_page
。 这里的逻辑不好(第二个if语句相反)。
尝试这个 :
if ($total_entries <= $per_page){
$output .= '1 to '.$total_entries;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.