我创建了自定义模板,其中我有显示结果,并且还应用分页来显示产品。当我更改永久链接到postname然后我的网址显示这样..
// localhost / traveler / root / 2 /和分页不起作用
如果我将固定链接设置为默认网址,就像这样...
// localhost / traveler / page_id = 21 /& page = 2并且分页工作正常
请建议解决这个问题?
我使用了以下代码进行分页:
<?php
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$limit =5;
$offset = ( $page - 1 ) * $limit;
?>
<?php $data = $wpdb->get_results("select * from table_name
LIMIT $offset,$limit ");?>
<?php
$total=$wpdb->get_results("select * from table_name ");
$pages = COUNT($total);
$pages = ceil($pages / $limit);
$querystring = "";
foreach ($_GET as $key => $value) {
if ($key != "page") $querystring .= "$key=$value&";
}
// Pagination
for ($i = 1; $i <= $pages; $i++)
{
echo "<a " . ($i == $page ? "class=\"page active\" " : "class=\"page gradient\"");
echo "href=\"?{$querystring}page=$i";
echo "\">$i</a> ";
}
$page1=$page;
$next=$page1+1;
echo "<a " . ($i == $page ? "class=\"page active\" " : "class=\"page gradient\"");
echo "href=\"?{$querystring}page=$next";
echo "\">Next</a> ";
?>