婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 網(wǎng)站建設(shè) > 建站知識(shí) > dedcms織夢(mèng)實(shí)現(xiàn)自定義字段進(jìn)行產(chǎn)品篩選

dedcms織夢(mèng)實(shí)現(xiàn)自定義字段進(jìn)行產(chǎn)品篩選

POST TIME:2021-05-23 01:31

企業(yè)dedecms網(wǎng)站中如果一些產(chǎn)品有很多不同的交叉屬性,就需要用到:1、后臺(tái)為該產(chǎn)品添加一些自定義的篩選字段 2、前臺(tái)根據(jù)這些字段逐層篩選 更方便客戶找到他需要的產(chǎn)品(文章)
本插件(文件)完全不動(dòng)dedecms 任何核心文件;
需要增加和修改的地方為:
1、進(jìn)行篩選的動(dòng)態(tài)php頁(yè)面;本篇在wwwroot/plus 下面增加 pcba.php頁(yè)面;
2、在模板目錄下增加用于顯示的模板文件;本篇在wwwroot/templets/default/ 下面增加 list_PCBA_with_type.htm 頁(yè)面;
3、在/include/文件價(jià)下找到 extend.func.php 文件 增加一些函數(shù)

本文僅作拋磚引玉(功能已實(shí)現(xiàn)),希望大家一起來(lái)完善(美化)該插件;

本人水平有限,還有很多不足之處;不過(guò)以下代碼已經(jīng)能將核心功能完成,也很實(shí)用(很多網(wǎng)友需要用到的)



1、在wwwroot/plus 下面增加 pcba.php頁(yè)面;
代碼如下:
------------------------------------------------------------------------------------------
<?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"];


//根據(jù)當(dāng)前URL中包含的查詢字符串進(jìn)行進(jìn)行篩選并返回所有符合條件的板卡的ID值,以逗號(hào)分隔
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;
}
//根據(jù)網(wǎng)址查詢的字段返回所有符合條件的板卡ID值集合,并輸出ID值集合中所有的產(chǎn)品
returnPCBAArc(returnQueryIDS($currentUrl));

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

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


2、在wwwroot/templets/default/ 下面增加 list_PCBA_with_type.htm 頁(yè)面
核心顯示代碼如下:

<div style="width:750px; float:left; padding-left:10px; height:150px; padding-top:7px; text-align:left; clear:both">
<table width="99%" border="0" cellspacing="0" cellpadding="0">

 
  <tr>
    <td valign="top" width="120px">板卡架構(gòu):</td>
    <td valign="top"><?php returnFieldValuesPHP($currentUrl,"jiagou","1"); ?>
</td>
  </tr>
 
    <tr>
    <td valign="top"> CPU 核心:</td>
    <td valign="top"> <?php returnFieldValuesPHP($currentUrl,"hexin","1"); ?>
</td>
  </tr>
<tr>
<td valign="top">應(yīng)用領(lǐng)域</td>
<td valign="top"><?php returnFieldValuesPHP($currentUrl,"hangye","1"); ?></td>
</tr>
<tr>
<td valign="top">板卡尺寸</td>
<td valign="top"><?php returnFieldValuesPHP($currentUrl,"type_size","1"); ?></td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
</tr>
</table>
</div>
-----------------------------------------------------------------------------------------


3、在/include/文件價(jià)下找到 extend.func.php 文件 增加以下函數(shù)

------------------------------------------------------------
//根據(jù)傳遞過(guò)來(lái)的多個(gè)以逗號(hào)拼接的產(chǎn)品ID,形成數(shù)組、查詢并返回相應(yīng)的產(chǎn)品
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 .="<DIV  style='float:left; border-right:1px #d0d9e2 solid; border-bottom:1px #d0d9e2 solid; width:332.6px;' >";
                $msg .="<UL class=productline_2><LI><DIV class=font14 style=overflow:hidden><SPAN style='FONT-WEIGHT: bold' id=BrandList_ctl06_lblSeriesName><a href=$url class='title' title='$aTitle'>$aTitle</a></SPAN> </DIV><DIV class=pic><a href=$url><img class='lazy' style='BORDER:none;WIDTH: 150px;' data-original=$picURL src='http://www.aiipc.com/templets/default//js/grey.gif' /></a></DIV>";
                $msg .="<DIV style='HEIGHT: 90px; OVERFLOW: hidden' class=intro><SPAN id=BrandList_ctl06_lblSeriesDescription><P><STRONG>$keydesc  </STRONG><BR>$gaisu</P></SPAN></DIV><SPAN class=text_o><a href=$url class=title>了解詳情></A></SPAN><div class=sc_size><div style=width: 80px class=left>功耗及尺寸:</div><span onmouseout=$(this).removeClass('size_a'); onmouseover=$(this).addClass('size_a'); class=size>$gonghao W </span> <span class=size>$size mm</span> </div></LI></UL></DIV>";
            }
       
    }
    print($msg);
}



//將數(shù)組轉(zhuǎn)化為查詢篩選字符串,類似&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 );
}
-----------------------------------------------------------------------

第三個(gè)函數(shù)最為關(guān)鍵

//獲取自定義字段所有值并附帶鏈接
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;
        }
        //將當(dāng)前路徑數(shù)組化
        $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){
                        //檢查當(dāng)前路徑中是否已經(jīng)存在某個(gè)查詢的自定義字段選項(xiàng),如存在則重新賦值,否則直接用"&"添加查詢字段
                        if(array_key_exists($customField, $data)){
                            $data[$customField] = $value;
                            //將路徑數(shù)組重新生成路徑
                            $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;
                        }
                   
                }else{
                    $newURl = $filename."?".$customField=$value;
                }
            $va = "<a href=".$newURl.">".$value."</a>    ";
            echo $va;
        }
    }
}


4、在后臺(tái)增加相應(yīng)的自定義字段,本示例增加的字段為:jiagou,hexin,hangye,type_size  ,均為checkBox多選類型

思路:
1、pcba.php 頁(yè)面作用:根據(jù)地址欄URL里面的篩選字段及值,找到所有符合條件的產(chǎn)品
2、extend.func.php 里面增加的 3個(gè)擴(kuò)展函數(shù) 用于比對(duì) 當(dāng)前URL里面篩選的條件(字段)的,如用戶要篩選的字段不在URL里面則增加、如用戶要篩選的字段在URL里面已存在則替換字段的值,并顯示在頁(yè)面。


收縮
  • 微信客服
  • 微信二維碼
  • 電話咨詢

  • 400-1100-266
主站蜘蛛池模板: 平乐县| 历史| 东至县| 马山县| 德惠市| 合作市| 蓝田县| 孝感市| 益阳市| 淳化县| 腾冲县| 永靖县| 青冈县| 芦溪县| 光泽县| 稻城县| 孝昌县| 韶关市| 西吉县| 贡嘎县| 东兰县| 福鼎市| 乐至县| 朝阳区| 玉田县| 景东| 九龙城区| 浮山县| 徐州市| 甘孜县| 栖霞市| 东明县| 南皮县| 昭觉县| 鄂温| 友谊县| 新宁县| 安多县| 隆德县| 北宁市| 修水县|