Home > Backend Development > PHP Tutorial > ECSHOP tutorial call classification article

ECSHOP tutorial call classification article

WBOY
Release: 2016-07-30 13:30:05
Original
1236 people have browsed it

In the past few days, I helped a friend build a shopping mall. I used ECSHOP. I feel that the ECSHOP function is indeed powerful enough. However, for people who do not understand the program, it is still quite complicated to use. It will take a lot of trouble to make a slight modification. If It would be nice to have a tag library like Dongyi does.
For example, when using Deep Blue, you need to call articles by category. This is a very common function, but the official does not provide it. I had to think of a way by myself, and finally found a way. Please take a look at the ECSHOP tutorial
The specific implementation method:
For example, the homepage calling method:
1. First open the index.php file and find the following code:

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


Add the following below it:

<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. The second step is to add the following code to the place where the index.dwt template wants to be called. (Note: Adjust the list of articles with a category ID of 8 in the above settings below):

<!--{<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


The call is successful according to the above method .

The above introduces the ECSHOP tutorial call classification article, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template