您现在的位置是:首页 > cms教程 > Ecshop商城教程Ecshop商城教程

ecshop调用指定dedecms织梦栏目文章列表

幼翠2023-12-12Ecshop商城教程已有人查阅

导读系统:dedecms + ecshop   实现步骤: 1.在文章模版goods.dwt添加一个新的库文件dede_articles.lbi themes/default/goods.dwt

系统:dedecms + ecshop   实现步骤: 1.在文章模版goods.dwt添加一个新的库文件dede_articles.lbi themes/default/goods.dwt,请根据你的目录结构修改,如果是首页,请在index.php中添加,栏目页在category.php中添加
<!-- #BeginLibraryItem "/library/dede_articles.lbi" --><!-- #EndLibraryItem -->
2.themes/default/library/dede_articles.lbi
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- {if $dede_articles} -->
<div class="h3Title"><h3>相关资讯</h3></div>
<ul class="brandList">
<!-- {foreach from=$dede_articles item=article} -->
<li><a href="{$article.url}" title="{$article.title}" rel="external">{$article.short_title|escape:html}
</a> </li>
<!-- {/foreach} -->
</ul>
<!-- {/if} -->
3.goods.php载入dede,请根据你的目录结构修改,如果是首页,请在index.php中添加,栏目页在category.php中添加。
define('IN_ECS', true);
/*载入dede*/
require_once(dirname(__FILE__)."/luxury/include/common.inc.php");
4.goods.php调用dede数据,如果是首页,请在index.php中添加,栏目页在category.php中添加
$smarty->assign('dede_articles', get_dede_articles()); //dede文章列表
5.get_dede_articles函数简单实现,如果是首页,请在index.php中添加,栏目页在category.php中添加。
/**
*
* 获取dedecms的文章
* @author http://www.heui.org
* @return 文章列表
*/
function get_dede_articles() {  //文档排序的方式
$orderby = 'rand';
$ordersql = '';
if($orderby=='hot' || $orderby=='click') $ordersql = " ORDER BY arc.click $orderWay";
else if($orderby == 'sortrank' || $orderby=='pubdate') $ordersql = " ORDER BY arc.sortrank $orderWay";
else if($orderby == 'id') $ordersql = "  ORDER BY arc.id $orderWay";
else if($orderby == 'near') $ordersql = " ORDER BY ABS(arc.id - ".$arcid.")";
else if($orderby == 'lastpost') $ordersql = "  ORDER BY arc.lastpost $orderWay";
else if($orderby == 'scores') $ordersql = "  ORDER BY arc.scores $orderWay";
else if($orderby == 'rand') $ordersql = "  ORDER BY rand()";
else $ordersql = " ORDER BY arc.sortrank $orderWay";
//limit条件
$line = 10;
$limit = trim(preg_replace('#limit#is', '', $limit));
if($limit!='') $limitsql = " LIMIT $limit ";
else $limitsql = " LIMIT 0,$line ";
$orwhere = '';
if(isset($orwheres[0])) {
$orwhere = join(' And ',$orwheres);
$orwhere = preg_replace("#^ And#is", '', $orwhere);
$orwhere = preg_replace("#And[ ]{1,}And#is", 'And ', $orwhere);
}
if($orwhere!='') $orwhere = " WHERE $orwhere ";
$addfieldsSql = '';
$addfieldsSqlJoin = '';
$sql =  "SELECT          arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,
tp.moresite,tp.siteurl,tp.sitepath
$addfieldsSql
FROM `dede_archives` arc left join `dede_arctype` tp on arc.typeid=tp.id
$addfieldsSqlJoin
$orwhere $ordersql $limitsql";
$res = $GLOBALS['db']->query($sql);
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$row['url'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],
$row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row
['moresite'],$row['siteurl'],$row['sitepath']);
$row['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?
sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];
$arr[] = $row;
}
return $arr;
}
总结:最主要是需要实现获取文章路径, 在这个案例中我们载入dede, 直接调用GetFileUrl提示:把$orwhere = '';改为$orwhere = 'arc.typeid=1';//表示调用栏目ID为1的文章列表 $line = 10;//返回记录数

本文标签:

很赞哦! ()

相关源码

  • (响应式H5)帝国cms7.5文章新闻博客模板带会员中心本模板基于帝国CMS内核开发,为新闻资讯、个人博客及作品展示类网站设计。采用响应式布局技术,确保在手机、平板和电脑等不同设备上都能获得良好的浏览体验。查看源码
  • 响应式pbootcms模板新闻资讯博客自媒体门户网站行业通用解决方案为新闻资讯、自媒体博客打造的响应式网站模板,同时支持企业门户、行业资讯等多场景快速适配。通过简单的图文替换即可实现跨行业转型,显著降低建站成本。查看源码
  • (PC+WAP)压缩机离心风机红色机械设备营销型网站pbootcms模板基于PbootCMS开发的压缩机/离心风机专用模板,助力机械设备企业构建高效营销平台;模板可编辑压缩机参数表、风机性能曲线等专业展示模块查看源码
  • (自适应响应式)蓝色律师事务所法务团队网站pbootcms模板为律师事务所和法律服务机构打造的专业网站模板,展现法律专业性与权威性,手工编写标准DIV+CSS代码,结构清晰优化,确保高效运行,自动适配电脑、平板和手机等各类设备,提供更好浏览体验查看源码
  • (PC+WAP)院校学院职业学校机构协会网站开源源码下载本模板基于PbootCMS系统开发,为高等院校、职业学校等教育机构设计,特别适合展示学校概况、院系设置、招生信息等内容。采用双端适配技术,确保在PC和移动设备上都能获得良好的浏览体验。查看源码
  • (自适应)英文绿色精密模具零件加工五金零件pbootcms外贸网站模板本模板基于PbootCMS开发,为五金零件、精密模具加工等英文外贸企业设计。采用响应式布局,适配各类移动设备,是五金零件企业开展国际贸易的专业展示平台。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐