ecshop在首页调用dedecms文章
ecshop的文章功能實在是太過于簡單了,所以我們為了豐富網站的內容,一般會集成DEDECMS來添加一些資訊文章,主要是DEDECMS文章處理相當強大,便于二次開發,下面通過兩大步驟實現ecshop在首頁調用dedecms文章:
一、在index.php中的添加和修改的兩步:
1、在index.php里載入DEDECMS數據庫文件,這樣才能查詢數據庫:
define('IN_ECS', true);
/*載入dede*/
require_once(dirname(__FILE__)."/dede/include/common.inc.php");
2、把查詢到的文章列表賦給dede_articles數組:
$smarty->assign('dede_articles', get_dede_articles()); //dede文章列表
3、獲取dedecms的文章
/**
?*
?* 獲取dedecms的文章
?* @author http://www.majiaping.com/
?* @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;
?
}
二、在模板文件index.dwt中兩步實現首頁調用DEDECMS文章
1、單獨建立一個模板文章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="http://blog.163.com/bgh1988@126/blog/{$article.url}"? title="{$article.title}" rel="external">{$article.short_title|escape:html}
?
</a>
??????? </li>
? <!-- {/foreach} -->
</ul>
<!-- {/if} -->
2、在index.dwt中需要顯示文章的地方包含dede_articles.lbi文件,實現ecshop首頁調用dedecms文章:
<!-- #BeginLibraryItem "/library/dede_articles.lbi" --><!-- #EndLibraryItem -->
轉載于:https://www.cnblogs.com/longailili/archive/2012/09/25/2701349.html
總結
以上是生活随笔為你收集整理的ecshop在首页调用dedecms文章的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++学习笔记九
- 下一篇: VS2010插件之NuGet