織夢二次開發(調用頂級欄目,調用父級欄目名稱,開啟文章副欄目,開啟文章頁當前欄目和鏈接)


一、調用頂級欄目的欄目信息

  include\taglib下 建立type2.lib.php文件放入以下代碼

<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Original Author <author@example.com> |
// | Your Name <you@example.com> |
// +----------------------------------------------------------------------+
//
// $Id:$

if (!defined('DEDEINC')) exit('Request Error!');
function lib_type2(&$ctag, &$refObj) {
global $dsql, $envs;
$attlist = 'typeid|0';
FillAttsDefault($ctag->CAttribute->Items, $attlist);
extract($ctag->CAttribute->Items, EXTR_SKIP);
$innertext = trim($ctag->GetInnerText());
if ($typeid == 0) {
$typeid = (isset($refObj->TypeLink->TypeInfos['topid']) ? $refObj->TypeLink->TypeInfos['topid'] : $envs['typeid']);
//echo "ssssssssss1".$refObj->TypeLink->TypeInfos['topid'];
//echo "ssssssssss2".$envs['typeid']; exit;
}
//echo "typeid:".$typeid; exit;
//lyy 如果topid==0 就是頂級分類,取當前記錄
if($refObj->TypeLink->TypeInfos['topid']==0){
$typeid=$refObj->TypeLink->TypeInfos['id'];
}
//echo "typeid:".$typeid; exit;
if (empty($typeid)) return '';
$row = $dsql->GetOne("SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
FROM `#@__arctype` WHERE id='$typeid'");

if (!is_array($row)) return '';
if (trim($innertext) == '') $innertext = GetSysTemplets("part_type_list.htm");
$dtp = new DedeTagParse();
$dtp->SetNameSpace('field', '[', ']');
$dtp->LoadSource($innertext);
if (!is_array($dtp->CTags)) {
unset($dtp);
return '';
} else {
//lyy 以下getTypeUrl($row[topid]錯的,換成 $row['id'] echo $row['id']."sssss";exit;

$row['typelink'] = GetTypeUrl($row['id'], MfTypedir($row['typedir']) , $row['isdefault'], $row['defaultname'], $row['ispart'], $row['namerule2'], $row['siteurl'], $row['sitepath']);

//print_r($row);exit;
foreach ($dtp->CTags as $tagid => $ctag) {
if (isset($row[$ctag->GetName() ])) $dtp->Assign($tagid, $row[$ctag->GetName() ]);
}
$revalue = $dtp->GetResult();
unset($dtp);
return $revalue;
}
} ?> 
頂級欄目

以后可以使用{dede:type2}    {/dede:type2}來調用頂級欄目的欄目id名稱鏈接等

二、調用父級欄目名稱

  打開include/taglib/type.lib.php 找到

$row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);

在其下面增加以下代碼

$row['parent_name'] = '';
        $row2= $dsql->GetOne("select topid from dao_arctype where id ='".$row['id']."'");
   $row['topid'] = $row2['topid'];
        
if($row['topid']){
 $row1 = $dsql->GetOne("select typename as parent_name from dao_arctype where id ='".$row['topid']."'");
   $row['parent_name'] = $row1['parent_name'];
  }
  else
     $row['parent_name'] = $row['typename']; //如果時頂級欄目,就顯示為該欄目名稱

前台模板那調用方法

<!--如果是內容頁模板,可以不用指定typeid,直接調用-->
{dede:type}[field:parent_name/]{/dede:type}
 
<!--在首頁或者列表頁模板,可指定typeid調用-->
{dede:type typeid='1'}[field:parent_name/]{/dede:type}

 

三、開啟文章副欄目

打開include\taglib\arclist.lib.php

將下面代碼注釋掉的查找到,替換為下面的

//if($CrossID=='') $orwheres[] = ' arc.typeid IN ('.GetSonIds($typeid).')';
//else $orwheres[] = ' arc.typeid IN ('.GetSonIds($typeid).','.$CrossID.')';
                if($CrossID=='')  $orwheres[] = ' (arc.typeid in ('.GetSonIds($typeid).') or FIND_IN_SET(\''.GetSonIds($typeid).'\',arc.typeid2)>0)';
            else $orwheres[] = $orwheres[] = ' (arc.typeid in (\''.GetSonIds($typeid).'\','.$CrossID.') or FIND_IN_SET('.GetSonIds($typeid).','.$CrossID.',arc.typeid2))';

副欄目前台可以顯示,但后台不顯示

 

四、開啟文章頁當前欄目和鏈接

 打開/include/arc.archives.class.php  搜索//設置全局環境變量  在下面增加2行

//設置全局環境變量
$this->Fields[ 'typename' ] = $this->TypeLink->TypeInfos[ 'typename' ];
$this->Fields['typelink'] = $this->TypeLink->GetOneTypeLink($this->TypeLink->TypeInfos);
$this->Fields['typeurl'] = $this->TypeLink->GetOneTypeUrl($this->TypeLink->TypeInfos);

然后再文章里面如果調用鏈接和名字的話就寫

帶鏈接的欄目名稱:{dede:field.typelink/} ,如:<a href="欄目鏈接地址">欄目名稱</a>
只要鏈接就是{dede:field.typeurl/} ,如:<a href="{dede:field.typeurl/}">{dede:field.typename/}</a>

參考內容:http://www.xhcss.com/xh/dedecms/jiaocheng/121.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM