我的页面每页有9个结果并显示1-5的分页,我的问题是如果我搜索的结果是一个或几个输入结果,我怎么能隐藏分页编号?
抱歉,如果我不发布所有代码,感谢您帮助我。
的sidebar.php
<div class="side-box-select cf">
<div class="side-select">
<select name="unit_size_x" class="side-box__select">
<option value="0" selected>Minimum</option>
<option value="10">10sqm</option>
<option value="20">20sqm</option>
<option value="30">30sqm</option>
<option value="40">40sqm</option>
<option value="50">50sqm</option>
<option value="60">60sqm</option>
<option value="70">70sqm</option>
<option value="80">80sqm</option>
<option value="90">90sqm</option>
<option value="100">100sqm</option>
</select>
</div>
<div class="side-select">
<select name="unit_size_y" class="side-box__select">
<option value="10">10sqm</option>
<option value="20">20sqm</option>
<option value="30">30sqm</option>
<option value="40">40sqm</option>
<option value="50">50sqm</option>
<option value="60">60sqm</option>
<option value="70">70sqm</option>
<option value="80">80sqm</option>
<option value="90">90sqm</option>
<option value="100">100sqm</option>
<option value="101" selected>Maximum</option>
</select>
</div>
的search.php
$metaquerysp[] = array(
'key'=>'unit_size',
'value'=>array( $unit_size_x, $unit_size_y ),
'compare'=>'BETWEEN',
'type'=>'NUMERIC',
);
<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'property',
'posts_per_page' => 9,
'orderby' => 'DATE',
'paged' => $paged,
'meta_query' => $metaquerysp
);?>
答案 0 :(得分:0)
希望这是有道理的。检查$query->post_count
以查看您的查询返回的帖子数量。
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
// Posts per page
$posts_per_page = 9;
// Should pagination show (default yes)
$pagination = true;
$args = array(
'post_type' => 'property',
'posts_per_page' => $posts_per_page,
'orderby' => 'DATE',
'paged' => $paged,
'meta_query' => $metaquerysp
);
// Run query
$query = new WP_Query($args);
// If query has less than $posts_per_page results, no pagination
if($query->post_count<$posts_per_page) {
$pagination = false;
}
// The loop
if($query->have_posts()) {
while($query->have_posts()) {
$query->the_post();
// Stuff
}
}
if($pagination) {
// show pagination
}