Ecshop Call Classification article, Ecshop invoke method of announcement

Source: Internet
Author: User
Tags foreach php file
Today encountered the issue of the article call, oneself on the Internet to check the information, the following methods are feasible, for the needs of friends reference. Oh

Specific implementation methods:
For example, the first page call method:
1. Open the index.php file first to find the following code:
$smarty->assign (' New_articles ', Index_get_new_articles ()); Latest Articles

Under it add the following:
Calling methods
<?php
$smarty->assign (' Class_articles_4 ', Index_get_class_articles (4,6));//Category Call article
//Call multiple parameters to change the passed in , and the variable received by the template, where 4 is the article category ID, where 6 is the number of calls
$smarty->assign (' Class_articles_5 ', Index_get_class_articles (5,6)); Category Call Article
$smarty->assign (' Class_articles_6 ', Index_get_class_articles (6,6));//Category call article
$smarty Assign (' Class_articles_7 ', Index_get_class_articles (7,6)); Category Call Article
$smarty->assign (' Class_articles_8 ', Index_get_class_articles (8,6));//Category call article
?>



Add the following function before the last?>
<?php function Index_get_class_articles ($cat _aid, $cat _num) {$sql = "Select article_id, Title,open_type,cat_id,file _url from ". $GLOBALS [' ECS ']->table (' article ')." WHERE cat_id = ". $cat _aid." and Is_open = 1 LIMIT ".
$cat _num;
$res = $GLOBALS [' db ']->getall ($sql);
$arr = Array ();
       foreach ($res as $idx = + $row) {$arr [$idx] [' id '] = $row [' article_id '];
       $arr [$idx] [' title '] = $row [' title '];
                                    $arr [$idx] [' short_title '] = $GLOBALS [' _cfg '] [' article_title_length '] > 0?
       Sub_str ($row [' title '], $GLOBALS [' _cfg '] [' article_title_length ']): $row [' title '];
       $arr [$idx] [' cat_name '] = $row [' Cat_name '];
       $arr [$idx] [' add_time '] = local_date ($GLOBALS [' _cfg '] [' date_format '], $row [' add_time ']);
                                    $arr [$idx] [' url '] = $row [' Open_type ']! = 1?
       Build_uri (' article ', Array (' aid ' = = $row [' article_id ']), $row [' title ']): Trim ($row [' File_url ']);  $arr [$idx] [' Cat_url ']   = Build_uri (' Article_cat ', array (' acid ' = = $row [' cat_id ')]);
} return $arr; }?>



2. The second step is to add the following code where the INDEX.DWT template wants to be called (Note: to downgrade the list of articles with category ID 8 in the above settings):

<!--{foreach from= $class _articles_8 item=article}-->
       <li><a href= "{$article. URL}" title= "{$ article.title|escape:html} "><!--{$article .short_title|truncate:15:true}--></a></li>
   <!--{/foreach}-->


The call succeeded by the method above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.