dedecms二次開發之內容頁輸出所屬篩選值+鏈接

2019-06-12 14:02:58 濟南網站建設

打開 /nclude/extend.func.php 在最下面加入


/**
 *  內容頁輸出所屬篩選值+鏈接
 *
 * @access    public
 * @param     string  $id文檔id
 * @param     string  $fieldsnamef單個篩選字段
 * @return    string
 */
function GetFilterUrl($id,$fieldsnamef)
{
global $dsql,$cfg_cmspath,$cfg_rewritea;
if (!isset($id) && !is_numeric($id))
{
return '';
}
else
{
$arcrow = $dsql->GetOne(" Select typeid,channel From `dede_archives` where id='$id' ");
$channelid = $arcrow['channel'];
$tid = $arcrow['typeid'];
$typerow = $dsql->GetOne(" Select typedir From `dede_arctype` where id='$tid' ");
$typedir = MfTypedir($typerow["typedir"]);
$channelrow = $dsql->GetOne("SELECT addtable FROM dede_channeltype where id='$channelid'");
$addtable = trim($channelrow['addtable']);
$fieldrow = $dsql->GetOne("SELECT $fieldsnamef FROM `$addtable` WHERE aid=$id");
}
$plist = $_SERVER['HTTP_X_REWRITE_URL'] ? string_filter($_SERVER['HTTP_X_REWRITE_URL']) : string_filter($_SERVER['REQUEST_URI']);
if($cfg_rewritea == 'Y')
{
$plist = stripos($plist, "makehtml_list_action.php") ? $cfg_cmspath.$typedir.'/' : $plist;//by<a href="http://www.lol9.cn" target="_blank"><u>六久閣</u></a> www.lol9.cn
$filterarr = string_filter(stripos($plist, ".html") ? str_replace(".html", "", $plist) : $cfg_cmspath.$typedir.'/');
}
else
{
$nofilter = (isset($_REQUEST['TotalResult']) ? "&TotalResult=".$_REQUEST['TotalResult'] : '').(isset($_REQUEST['PageNo']) ? "&PageNo=".$_REQUEST['PageNo'] : '');
$filterarr = string_filter(stripos($plist, "list.php?tid=") ? str_replace($nofilter, '', $plist) : $GLOBALS['cfg_cmsurl']."/plus/list.php?tid=".$tid);
}
$cInfos = $dsql->GetOne(" Select * From  `dede_channeltype` where id='$channelid' ");
$fieldset = $cInfos['fieldset'];
$dtp = new DedeTagParse();
    $dtp->SetNameSpace('field','<','>');
    $dtp->LoadSource($fieldset);
    $result = '';
    if(is_array($dtp->CTags))
    {
foreach($dtp->CTags as $tida=>$ctag)
        {
            $field_name = $ctag->GetName();
$fieldsname = $fieldsnamef ? explode(",", $fieldsnamef) : explode(",", $field_name);
if( in_array($field_name, $fieldsname))
{
if($cfg_rewritea == 'Y')
{
$href = "";
$addonfields_items = explode(",",$ctag->GetAtt('default'));
$i = array_search($fieldrow[$fieldsnamef],explode(",",$ctag->GetAtt('default')));
$filterarr1 = explode("list_", $filterarr);
$href = $filterarr1[0]."list_".$tid.'_'.$field_name.'_'.$i;
$href .= ".html";
$href = str_replace(array("_".$field_name.".",".","_".$_REQUEST['TotalResult']."_".$_REQUEST['PageNo']),array(".",".",""),$href);
$result .= '<a href="'.$href.'">'.$addonfields_items[$i].'</a>';
}
else
{
$addonfields_items = explode(",",$ctag->GetAtt('default'));
$i = array_search($fieldrow[$fieldsnamef],explode(",",$ctag->GetAtt('default')));
$href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);
$href = str_replace("&TotalResult=".$_REQUEST['TotalResult']."&PageNo=".$_REQUEST['PageNo'], "", $href);
$result .= '<a title="'.$addonfields_items[$i].'" href="'.$href.'">'.$addonfields_items[$i].'</a>';
}
}
        }
    }
return $result;
}

dedecms內容頁模板中調用標簽

<small>區域:</small>{dede:field.id function=GetFilterUrl(@me,'area')/}

<small>地鐵:</small>{dede:field.id function=GetFilterUrl(@me,'subway')/}

標紅的地方是你的篩選字段名

 

dedecms首頁/列表頁調用標簽

區域:[field:id function=function=GetFilterUrl(@me,'area')/]

地鐵:[field:id function=function=GetFilterUrl(@me,'subway')/]


久久爱免费视顿在线观看_人人天天夜夜日日狠狠_超碰在线观看天天操_得得的爱免费视频观看