dedecms给分类栏目增加不同的友情链接

2012-04-02 10:16 来源:www.chinab4c.com 作者:dedecms专家

     dedecms给分类栏目增加不同的友情链接,这个是每个人都梦想的一件事情,如果能让dedecms不同栏目支持不同的友情链接,这将为我们的网站外链处理提供很大的便利。

   1:修改dedecms数据库结构。alter table dede_flink add column typeid1 int(1) default 0;

   2:friendlink_add.php

   require_once(DEDEADMIN."/inc/inc_catalog_options.php");

  $query = "INSERT INTO `dede_flink`(sortrank,url,webname,logo,msg,email,typeid,dtime,ischeck,typeid1)
            VALUES('$sortrank','$url','$webname','$imgurl','$msg','$email','$typeid','$dtime','$ischeck','$typeid1'); ";

   3:friendlink_edit.php

    require_once(DEDEADMIN."/inc/inc_catalog_options.php");

    $query = "UPDATE `dede_flink` SET sortrank='$sortrank',url='$url',webname='$webname',logo='$logo',msg='$msg',
                  email='$email',typeid='$typeid',typeid1='$typeid1',ischeck='$ischeck' WHERE id='$id' ";

  4:friendlink_edit.htm增加以下代码

   <?php
   
          $typeOptions = GetOptionList($myLink['typeid1'],$cuserLogin->getUserChannel());
          echo "<select name='typeid1' id='typeid1' style='width:240px'>\r\n";
          echo "<option value='0'>请选择栏目...</option>\r\n";
          echo $typeOptions;
          echo "</select>";
   ?>

   5:增加自定义标签

   function lib_aflink(&$ctag,&$refObj)
{
 
    global $dsql,$cfg_soft_lang;
    $attlist="type|textall,row|24,titlelen|24,linktype|1,typeid|0|typeid1|0";
 
    FillAttsDefault($ctag->CAttribute->Items,$attlist);
    extract($ctag->CAttribute->Items, EXTR_SKIP);
  

 $totalrow = $row;
    $revalue = '';
  
  
    if(trim($ctag->GetInnerText())=='') $innertext = "<li>[field:link /]</li>";
    else $innertext = $ctag->GetInnerText();
    $equery = "SELECT * FROM dede_flink where typeid1= ".$refObj->Fields['id']." order by sortrank asc limit 0,10";
 
    $dsql->SetQuery($equery);
    $dsql->Execute();
   
    while($dbrow=$dsql->GetObject())
    { 
        if($type=='text'||$type=='textall')
        {
            $link = "<a href='".$dbrow->url."' target='_blank'>".cn_substr($dbrow->webname,$titlelen)."</a> ";
        }
        else if($type=='image')
        {
            $link = "<a href='".$dbrow->url."' target='_blank'><img src='".$dbrow->logo."' width='88' height='31' border='0'></a> ";
        }
        else
        {
            if($dbrow->logo=='')
            {
                $link = "<a href='".$dbrow->url."' target='_blank'>".cn_substr($dbrow->webname,$titlelen)."</a> ";
            }
            else
            {
                $link = "<a href='".$dbrow->url."' target='_blank'><img src='".$dbrow->logo."' width='88' height='31' border='0'></a> ";
            }
        }
  
        $rbtext = preg_replace("/\[field:url([\/\s]{0,})\]/isU", $row['url'], $innertext);
  echo $rbtext;
         $rbtext = preg_replace("/\[field:webname([\/\s]{0,})\]/isU", $row['webname'], $rbtext);
         $rbtext = preg_replace("/\[field:logo([\/\s]{0,})\]/isU", $row['logo'], $rbtext);
         $rbtext = preg_replace("/\[field:link([\/\s]{0,})\]/isU", $link, $rbtext);
         $revalue .= $rbtext;
    }

    return $revalue;
}

6:dedecms模板调用

{dede:aflink }{/dede:aflink}