立即登录 注册新帐号

http://www.chutianz.com - 楚天站长站

会员投稿 匿名投稿 投稿指南 RSS订阅 楚天站长站推荐:
搜索: 您的位置主页 > 网站运营 > 建站经验 > 阅读资讯:dede5.7添加自定义标签显示非dede表数据

dede5.7添加自定义标签显示非dede表数据

2012-05-03 10:06:13 来源:www.chutianz.com 【 】 点击:我要投稿 发表评论

需求:调用一个商城系统里面的产品数据到dedecms文章页,希望对需要类似需求的人有所帮助
功能实现:为了不用垮数据库查询,dedecms安装到商城系统数据库里面
下面是实现的代码(请根据自己的环境进行修改)
include/taglib/hongyungoods.lib.php

  <?php
/**
 * @author http://www.heui.org/
 */
if(!defined('DEDEINC')) exit('Request Error!');
 
functionlib_hongyungoods(&$ctag, &$refObj)
{
    global$dsql, $envs, $cfg_cmsurl;
 
    //属性处理
    $attlist="row|6,titlelen|0,tid|0";
    FillAttsDefault($ctag->CAttribute->Items,$attlist);
    extract($ctag->CAttribute->Items, EXTR_SKIP);
 
    //只在指定栏目显示
    if($tid>0 && $tid!= $envs['typeid']) return'';
 
    if( !$dsql->IsTable("sl_products") ) return'没安装鸿运产品模块';
 
    $innertext= $ctag->GetInnerText();
    //@todo hongyungoods.htm
    if(trim($innertext)=='') $innertext= GetSysTemplets("hongyungoods.htm");
 
    //@todo 智能条件
    $where= 1;
    $limit= 5;
 
    $ctp= newDedeTagParse();
    $ctp->SetNameSpace('field', '[', ']');
    $ret= '';
    $query= "SELECT p.`Name` AS title,
 CONCAT('http://www.hongyun2000.com/', ps.`AcStr`, '-view-', p.`ID`, '.html') AS url,
 CONCAT('http://www.hongyun2000.com/uploadfile/s/', p.`Images`) AS img
 FROM `sl_products` AS p
 LEFT JOIN `sl_products_sort` AS ps ON p.`SID` = ps.`ID`
 WHERE " . $where . "ORDER BY RAND() LIMIT " . $limit;
 
    $dsql->Execute('me',$query);
  while($rs= $dsql->GetArray('me'))
  {
      $rs['title'] = 0 == $titlelen?$rs['title']:cn_substr($rs['title'], $titlelen);
        $ctp->LoadSource($innertext);
      foreach($ctp->CTags as$tagid=>$ctag) {
            if(!empty($rs[strtolower($ctag->GetName())])) {
                $ctp->Assign($tagid,$rs[$ctag->GetName()]);
            }
          }
          $ret.= $ctp->GetResult();
  }
 
  return$ret;
}
 
?>

调用页面使用:

 

{dede:hongyungoods}
<dd>
    <spanclass="tlink"><ahref="[field:url/]"><imgsrc="[field:img/]"alt="[field:title/]"/></a>
    <ahref="[field:url/]"target="_blank">[field:title/]</a></span>
</dd>
{/dede:hongyungoods}

感谢 靓哥 的投稿 本文仅代表作者观点,与楚天站长站立场无关。

分享到:

数据统计中!!

tags:,楚天站长站www.chutianz.com

 责任编辑:毛新红
  • 评论总数: [ 查看全部 ] 网友评论