dedcms织梦实现自定义字段进行产品筛选

dedcms织梦实现自定义字段进行产品筛选,第1张

dedcms织梦实现自定义字段进行产品筛选 企业dedecms网站中如果一些产品有很多不同的交叉属性,就需要用到:1、后台为该产品添加一些自定义的筛选字段 2、前台根据这些字段逐层筛选 更方便客户找到他需要的产品(文章)
本插件(文件)完全不动dedecms 任何核心文件;
需要增加和修改的地方为:
1、进行筛选的动态php页面;本篇在wwwroot/plus 下面增加 pcba.php页面;
2、在模板目录下增加用于显示的模板文件;本篇在wwwroot/templets/default/ 下面增加 list_PCBA_with_type.htm 页面;
3、在/include/文件价下找到 extend.func.php 文件 增加一些函数

本文仅作抛砖引玉(功能已实现),希望大家一起来完善(美化)该插件;

本人水平有限,还有很多不足之处;不过以下代码已经能将核心功能完成,也很实用(很多网友需要用到的)



1、在wwwroot/plus 下面增加 pcba.php页面;
代码如下:
------------------------------------------------------------------------------------------

require_once("../ouyp/config.php");
require_once(DEDEINC."/dedetag.class.php");
require_once(dirname(__FILE__).'/../include/common.inc.php');
require_once(DEDEINC."/extend.func.php");

$currentUrl = $_SERVER["REQUEST_URI"];


//根据当前URL中包含的查询字符串进行进行筛选并返回所有符合条件的板卡的ID值,以逗号分隔
function returnQueryIDS($url){
    $data = array();
    $parameter = explode('&',end(explode('?',$url)));
    $addquery = count($parameter);
    foreach($parameter as $val){
        $tmp = explode('=',$val);
        $data[$tmp[0]] = $tmp[1];
    }
    $query = $query."and".$tmp[0];
    if($addquery == '1'){
        foreach ($data as $key => $value) {
            $value = urldecode($value);
            $query = "SELECt * FROM `waimaomoban_pcba` WHERe FIND_IN_SET('$value',$key)";
        }
    }else {
        $firstquery = array_slice($data,0,1);
        $otherquery = array_slice($data,1);
        foreach ($firstquery as $key => $value) {
            $value = urldecode($value);
            $query = "SELECt * FROM `waimaomoban_pcba` WHERe FIND_IN_SET('$value',$key)"; 
        }
        foreach ($otherquery as $key => $value) {
            $value = urldecode($value);
            $query = $query." and FIND_IN_SET('$value',$key)";
        }
    }
    $orderby = ' order by aid desc ';
    $query = $query.$orderby;
    if($addquery !== 0){
        global $dsql;
        $array = array();
        $dsql->SetQuery($query);
        $dsql->Execute();
        while($row = $dsql->GetArray())
        {
            $aids = array_push($array,$row['aid']);
        }
        $aids = join(",",$array);
    }else{
            $aids = 0;
    }
    return $aids;
}
//根据网址查询的字段返回所有符合条件的板卡ID值集合,并输出ID值集合中所有的产品
returnPCBAArc(returnQueryIDS($currentUrl));

require_once(DEDETEMPLATE.'/default/list_PCBA_with_type.htm');

-------------------------------------------------------------------------------------------


2、在wwwroot/templets/default/ 下面增加 list_PCBA_with_type.htm 页面
核心显示代码如下:




 
  
    板卡架构:
    

  
 
    
     CPU 核心:
    

  

应用领域



板卡尺寸








-----------------------------------------------------------------------------------------


3、在/include/文件价下找到 extend.func.php 文件 增加以下函数

------------------------------------------------------------
//根据传递过来的多个以逗号拼接的产品ID,形成数组、查询并返回相应的产品
function returnPCBAArc($qstr,$orderby='id',$desc ='desc')
{
    global $dsql;
    if(!empty($qstr))
    {
        $arcids = preg_replace("#[^0-9,]#", '', preg_replace("#,#", ',', $qstr));
       
            $query = "SELECT * FROM `waimaomoban_archives` WHERe id in($arcids) order by $orderby $desc";
            $dsql->SetQuery($query);
            $dsql->Execute();
            while($row = $dsql->GetArray())
            {
                $url = GetoneArchiveUrl($row['id']);
                $aTitle = $row['title'];
                $picURL = $row['litpic'];
                $gonghao = $row['gonghao'];
                $size = $row['size'];
                $gaisu = $row['gaisu'];
                $keydesc = $row['keydesc'];
               
                $msg .=" style='float:left; border-right:1px #d0d9e2 solid; border-bottom:1px #d0d9e2 solid; width:332.6px;' >";
                $msg .="
  • $aTitle ";
                    $msg .="

    $keydesc  
    $gaisu

    了解详情>功耗及尺寸:$gonghao W $size mm
";
            }
       
    }
    print($msg);
}



//将数组转化为查询筛选字符串,类似&a=111&b=222
function array_implode($glue, $separator, $array) {
     if ( ! is_array( $array ) ) return $array;
     $string = array();
     foreach ( $array as $key => $val ) {
         if ( is_array( $val ) )
             $val = implode( ',', $val );
         $string[] = "{$key}{$glue}{$val}";
    }
     return implode( $separator, $string );
}
-----------------------------------------------------------------------

第三个函数最为关键

//获取自定义字段所有值并附带链接
function returnFieldValuesPHP($currentURl,$customField,$type='',$id='17')
{
    global $dsql;
    if(!empty($customField))
    {
        $fname = $customField;
        $row = $dsql->GetOne("SELECt fieldset,'' as maintable,addtable,issystem FROM `waimaomoban_channeltype` WHERe id='$id'");
        $fieldset = $row['fieldset'];
        $trueTable = $row['addtable'];
        $dtp = new DedeTagParse();
        $dtp->SetNameSpace("field", "<", ">");
        $dtp->LoadSource($fieldset);
        foreach($dtp->CTags as $ctag)
        {
            if(strtolower($ctag->GetName())==strtolower($fname)) break;
        }
        //将当前路径数组化
        $parameter = explode('&',end(explode('?',$currentURl)));
        $addquery = count($parameter);
        foreach($parameter as $val){
            $tmp = explode('=',$val);
            $data[$tmp[0]] = $tmp[1];
        }
       
        $rowValue = explode(",",$ctag->GetAtt('default'));
        $filename = "pcba.php";
        foreach($rowValue as $key=>$value)
        {
                if($addquery !== 0){
                        //检查当前路径中是否已经存在某个查询的自定义字段选项,如存在则重新赋值,否则直接用"&"添加查询字段
                        if(array_key_exists($customField, $data)){
                            $data[$customField] = $value;
                            //将路径数组重新生成路径
                            $newdata = array();
                            $newdata = $data;
                           
                            $firstquery = array_slice($newdata,0,1);
                            $otherquery = array_slice($newdata,1,5);
                            foreach($firstquery as $k1 =>$v1){
                                $fURl = $filename."?".$k1."=".$v1;
                            }
                           
                            if(count($otherquery) !== 0){
                                next(implode("&", $otherquery));
                                $query = array_implode( '=', '&', $otherquery);
                                //print_r($query);
                                $newURl = $fURl."&".$query ;
                            }else{
                                $newURl = $fURl;
                            }
                        }else{
                            $newURl = $currentURl."&".$customField."=".$value;
                        }
                   

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/3007979.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-09-27
下一篇 2022-09-27

发表评论

登录后才能评论

评论列表(0条)

保存