Home > php教程 > php手册 > body text

ECSHOP教程之调用分类文章,

WBOY
Release: 2016-06-13 08:56:01
Original
1218 people have browsed it

ECSHOP教程之调用分类文章,

这几天帮一个朋友弄一个商城,用的是ECSHOP,感觉ECSHOP功能确实够 强大,但是对于不懂程序的人来说,使用起来还是挺复杂,稍微做点修改就得大费周折,如果能像动易那样出一套标签库就好了。

比如深蓝使用的时候需要按分类调用一下文章,这是一个很常见的功能,可以官方并没有提供,只好自己想办法,最后终于找到了办法。请看一下ECSHOP教程

具体实现方法:
举例如首页调用方法:
1、先打开index.php文件找到以下代码:

$smarty->assign(<span>'</span><span>new_articles</span><span>'</span>, index_get_new_articles()); <span>//</span><span> 最新文章</span>
Copy after login



在它下面增加以下:

<span>//</span><span>调用方法</span>
<span>
$smarty</span>->assign(<span>'</span><span>class_articles_4</span><span>'</span>, index_get_class_articles(<span>4</span>,<span>6</span>)); <span>//</span><span> 分类调用文章
</span><span>//</span><span>调用多个就修改传进去的参数,以及模板接收的变量,其中上面的4就是文章分类ID,其中6是调用数量</span>
$smarty->assign(<span>'</span><span>class_articles_5</span><span>'</span>, index_get_class_articles(<span>5</span>,<span>6</span>)); <span>//</span><span> 分类调用文章</span>
$smarty->assign(<span>'</span><span>class_articles_6</span><span>'</span>, index_get_class_articles(<span>6</span>,<span>6</span>)); <span>//</span><span> 分类调用文章</span>
$smarty->assign(<span>'</span><span>class_articles_7</span><span>'</span>, index_get_class_articles(<span>7</span>,<span>6</span>)); <span>//</span><span> 分类调用文章</span>
$smarty->assign(<span>'</span><span>class_articles_8</span><span>'</span>, index_get_class_articles(<span>8</span>,<span>6</span>)); <span>//</span><span> 分类调用文章</span>
Copy after login

<span>//</span><span>在最后?>这个之前增加以下函数</span>
<span>


function index_get_class_articles($cat_aid, $cat_num)
{
$sql </span>= <span>"</span><span>SELECT article_id, title,open_type,cat_id,file_url FROM </span><span>"</span> .$GLOBALS[<span>'</span><span>ecs</span><span>'</span>]->table(<span>'</span><span>article</span><span>'</span>). <span>"</span><span> WHERE cat_id = </span><span>"</span>.$cat_aid.<span>"</span><span> and is_open = 1 LIMIT </span><span>"</span><span> . $cat_num;
$res </span>= $GLOBALS[<span>'</span><span>db</span><span>'</span>]-><span>getAll($sql);
$arr </span>=<span> array();
</span><span>foreach</span> ($res AS $idx =><span> $row)
{
       $arr[$idx][</span><span>'</span><span>id</span><span>'</span>]       = $row[<span>'</span><span>article_id</span><span>'</span><span>];
       $arr[$idx][</span><span>'</span><span>title</span><span>'</span>]    = $row[<span>'</span><span>title</span><span>'</span><span>];
       $arr[$idx][</span><span>'</span><span>short_title</span><span>'</span>] = $GLOBALS[<span>'</span><span>_CFG</span><span>'</span>][<span>'</span><span>article_title_length</span><span>'</span>] > <span>0</span> ?<span>
                                    sub_str($row[</span><span>'</span><span>title</span><span>'</span>], $GLOBALS[<span>'</span><span>_CFG</span><span>'</span>][<span>'</span><span>article_title_length</span><span>'</span>]) : $row[<span>'</span><span>title</span><span>'</span><span>];
       $arr[$idx][</span><span>'</span><span>cat_name</span><span>'</span>] = $row[<span>'</span><span>cat_name</span><span>'</span><span>];
       $arr[$idx][</span><span>'</span><span>add_time</span><span>'</span>] = local_date($GLOBALS[<span>'</span><span>_CFG</span><span>'</span>][<span>'</span><span>date_format</span><span>'</span>], $row[<span>'</span><span>add_time</span><span>'</span><span>]);
       $arr[$idx][</span><span>'</span><span>url</span><span>'</span>]       = $row[<span>'</span><span>open_type</span><span>'</span>] != <span>1</span> ?<span>
                                    build_uri(</span><span>'</span><span>article</span><span>'</span>, array(<span>'</span><span>aid</span><span>'</span> => $row[<span>'</span><span>article_id</span><span>'</span>]), $row[<span>'</span><span>title</span><span>'</span>]) : trim($row[<span>'</span><span>file_url</span><span>'</span><span>]);
       $arr[$idx][</span><span>'</span><span>cat_url</span><span>'</span>]     = build_uri(<span>'</span><span>article_cat</span><span>'</span>, array(<span>'</span><span>acid</span><span>'</span> => $row[<span>'</span><span>cat_id</span><span>'</span><span>]));
}
</span><span>return</span><span> $arr;
}</span>
Copy after login



2、第二步是在index.dwt模板想调用的地方增加以下代码,(注:以下调上面设置里的分类ID为8的文章列表):

<!--{<span>foreach</span> <span>from</span>=$class_articles_8 item=article}-->
       <li><a href=<span>"</span><span>{$article.url}</span><span>"</span> title=<span>"</span><span>{$article.title|escape:html}</span><span>"</span>><!--{$article.short_title|truncate:<span>15</span>:<span>true</span>}--></a></li>
   <!--{/<span>foreach</span>}-->
Copy after login

 



按以上方法调用成功。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template