wordpress框架搜索功能+分页+排序
Posted qq_39476250
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wordpress框架搜索功能+分页+排序相关的知识,希望对你有一定的参考价值。
<div class="text1">
<a href="">
<h3>全部<strong>(<?php echo $c['count(id)']; ?>)</strong>
</h3>
</a>
</div>
<button style="float:right; width:90px; height:30px;">搜索商户</button>
<input style="float:right;" type="text" name="ss">
$count = $wpdb->get_results("SELECT count(id) FROM wp_shangjia");
$c = (array)$count['0'];
$ss = $_GET['ss'];
$count1 = $wpdb->get_results("SELECT count(id) FROM wp_shangjia where sh_name like '%$ss%'");
$c1 = (array)$count1['0'];
if($ss){
$pageSize = 7; //每页显示数据条数
$totalNum = $c1['count(id)'];//数据总条数
$totalPageCount = intval($totalNum/$pageSize); //总页数
$nowPage = isset($_GET['page1']) ? intval($_GET['page1']) : 1;//判断当前页是哪一页
$prev = ($nowPage-1 <= 0) ? 1 : $nowPage-1;//上一页
$next = ($nowPage+1 >= $totalPageCount) ? $nowPage+1 : $totalPageCount;//下一页
$offset = ($nowPage-1)*$pageSize;//偏移量
$data = $wpdb->get_results("SELECT * FROM wp_shangjia where sh_name like '%$ss%' order by id limit $offset,$pageSize");
$count = $wpdb->get_results("SELECT count(id) FROM wp_shangjia where sh_name like '%$ss%'");
$c = (array)$count['0'];
}else{
$pageSize = 7; //每页显示数据条数
$totalNum = $c['count(id)'];//数据总条数
$totalPageCount = intval($totalNum/$pageSize); //总页数
$nowPage = isset($_GET['page1']) ? intval($_GET['page1']) : 1;//判断当前页是哪一页
$prev = ($nowPage-1 <= 0) ? 1 : $nowPage-1;//上一页
$next = ($nowPage+1 >= $totalPageCount) ? $nowPage+1 : $totalPageCount;//下一页
$offset = ($nowPage-1)*$pageSize;//偏移量
$data = $wpdb->get_results("SELECT * FROM wp_shangjia order by id limit $offset,$pageSize");
$count = $wpdb->get_results("SELECT count(id) FROM wp_shangjia");
$c = (array)$count['0'];
}
if($_GET['page1']){
$dq = $_GET['page1'];
$x = (($dq-1)*$pageSize);
}
foreach ($data as $k => $v){
$v = (array)$v;
$x = $x+1;
echo $x;
}
<div class="fenye" style="float:right;">
<?php if($ss){ ?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?ss=<?php echo $ss; ?>&page1=1">首页</a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?ss=<?php echo $ss; ?>&page1=<?php echo $prev; ?>">上一页</a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?ss=<?php echo $ss; ?>&page1=<?php echo $next; ?>">下一页</a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?ss=<?php echo $ss; ?>&page1=<?php echo $totalPageCount; ?>">尾页</a>
<?php }else{ ?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?page1=1">首页</a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?page1=<?php echo $prev; ?>">上一页</a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?page1=<?php echo $next; ?>">下一页</a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?page1=<?php echo $totalPageCount; ?>">尾页</a>
<?php } ?>
</div>
以上是关于wordpress框架搜索功能+分页+排序的主要内容,如果未能解决你的问题,请参考以下文章