之前有个客户找点启资源做wordpress多重筛选功能,主要通过自定义分类法来筛选。下面给出大致的代码片段,供有一定开发基础的人看,若不懂代码,可联系点启资源开发。
处理过滤的代码:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'paged' => $paged
);
$args['tax_query'] = array();
if(isset($_GET['city']) && $_GET['city'] > 0){
array_push($args['tax_query'], array('taxonomy' => 'city','field' => 'term_id','terms' => $_GET['city']) );
}
if(isset($_GET['function']) && $_GET['function'] > 0){
array_push($args['tax_query'], array('taxonomy' => 'function','field' => 'term_id','terms' => $_GET['function']) );
}
if(isset($_GET['industry']) && $_GET['industry'] > 0){
array_push($args['tax_query'], array('taxonomy' => 'industry','field' => 'term_id','terms' => $_GET['industry']) );
}
if(isset($_GET['scene']) && $_GET['scene'] > 0){
array_push($args['tax_query'], array('taxonomy' => 'scene','field' => 'term_id','terms' => $_GET['scene']) );
}
if(isset($_GET['price']) && $_GET['price'] > 0){
array_push($args['tax_query'], array('taxonomy' => 'price','field' => 'term_id','terms' => $_GET['price']) );
}
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
endwhile;endif;?>
获取过滤链接的函数
function getFilterUrl($city,$function,$industry,$price,$scene=0){
$filter = '?filter=1';
if( $city ){
$filter .= '&city='.$city;
}else{
$filter .= '&city=0';
}
if( $function ){
$filter .= '&function='.$function;
}else{
$filter .= '&function=0';
}
if($scene){
if( $industry ){
$filter .= '&scene='.$industry;
}else{
$filter .= '&scene=0';
}
}else{
if( $industry ){
$filter .= '&industry='.$industry;
}else{
$filter .= '&industry=0';
}
}
if( $price ){
$filter .= '&price='.$price;
}else{
$filter .= '&price=0';
}
return $filter;
}
另附一个案例核心代码下载:https://pan.baidu.com/s/1slfXikH 密码: g8c9
原文链接:https://www.dqzy.cn/2025/05/08/531.html,转载请注明出处。
1、本站所有源码资源(包括源代码、软件、学习资料等)仅供研究学习以及参考等合法使用,请勿用于商业用途以及违法使用。如本站不慎侵犯您的版权请联系我们,我们将及时处理,并撤下相关内容!
2、访问本站的用户必须明白,本站对所提供下载的软件和程序代码不拥有任何权利,其版权归该软件和程序代码的合法拥有者所有,请用户在下载使用前必须详细阅读并遵守软件作者的“使用许可协议”,本站仅仅是一个学习交流的平台。
3、如下载的压缩包需要解压密码,若无特殊说明,那么文件的解压密码则为:www.dqzy.cn。
4、点启资源网是一个免费且专业分享网站源码、图片素材、特效代码、教程文章、站长工具的平台。我们努力给站长提供好的资源!


评论0