Home Backend Development PHP Tutorial ECSHOP tutorial call classification article

ECSHOP tutorial call classification article

Jul 30, 2016 pm 01:30 PM
class index title

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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What file is index.html? What file is index.html? Feb 19, 2024 pm 01:36 PM

index.html represents the home page file of the web page and is the default page of the website. When a user visits a website, the index.html page is usually loaded first. HTML (HypertextMarkupLanguage) is a markup language used to create web pages, and index.html is also an HTML file. It contains the structure and content of a web page, as well as tags and elements used for formatting and layout. Here is an example index.html code: &lt

How to use classes and methods in Python How to use classes and methods in Python Apr 21, 2023 pm 02:28 PM

Concepts and instances of classes and methods Class (Class): used to describe a collection of objects with the same properties and methods. It defines the properties and methods common to every object in the collection. Objects are instances of classes. Method: Function defined in the class. Class construction method __init__(): The class has a special method (construction method) named init(), which is automatically called when the class is instantiated. Instance variables: In the declaration of a class, attributes are represented by variables. Such variables are called instance variables. An instance variable is a variable modified with self. Instantiation: Create an instance of a class, a specific object of the class. Inheritance: that is, a derived class (derivedclass) inherits the base class (baseclass)

Replace the class name of an element using jQuery Replace the class name of an element using jQuery Feb 24, 2024 pm 11:03 PM

jQuery is a classic JavaScript library that is widely used in web development. It simplifies operations such as handling events, manipulating DOM elements, and performing animations on web pages. When using jQuery, you often encounter situations where you need to replace the class name of an element. This article will introduce some practical methods and specific code examples. 1. Use the removeClass() and addClass() methods jQuery provides the removeClass() method for deletion

What does class mean in python? What does class mean in python? May 21, 2019 pm 05:10 PM

Class is a keyword in Python, used to define a class. The method of defining a class: add a space after class and then add the class name; class name rules: capitalize the first letter. If there are multiple words, use camel case naming, such as [class Dog()].

Detailed explanation of PHP Class usage: Make your code clearer and easier to read Detailed explanation of PHP Class usage: Make your code clearer and easier to read Mar 10, 2024 pm 12:03 PM

When writing PHP code, using classes is a very common practice. By using classes, we can encapsulate related functions and data in a single unit, making the code clearer, easier to read, and easier to maintain. This article will introduce the usage of PHPClass in detail and provide specific code examples to help readers better understand how to apply classes to optimize code in actual projects. 1. Create and use classes In PHP, you can use the keyword class to define a class and define properties and methods in the class.

Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? Aug 26, 2023 pm 10:58 PM

Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? In Vue development, we often use the v-bind instruction to dynamically bind class and style, but sometimes we may encounter some problems, such as being unable to correctly use v-bind to bind class and style. In this article, I will explain the cause of this problem and provide you with a solution. First, let’s understand the v-bind directive. v-bind is used to bind V

what does title mean what does title mean Aug 04, 2023 am 11:18 AM

Title is the meaning that defines the title of the web page. It is located within the tag and is the text displayed in the title bar of the browser. Title is very important for the search engine optimization and user experience of the web page. When writing HTML web pages, you should pay attention to using relevant keywords and attractive descriptions to define the title element to attract more users to click and browse.

How SpringBoot encrypts and protects class files through custom classloader How SpringBoot encrypts and protects class files through custom classloader May 11, 2023 pm 09:07 PM

Background Recently, key business codes have been encrypted for the company framework to prevent the engineering code from being easily restored through decompilation tools such as jd-gui. The configuration and use of the related obfuscation scheme are relatively complex and there are many problems for the springboot project, so the class files are encrypted and then passed The custom classloder is decrypted and loaded. This solution is not absolutely safe. It only increases the difficulty of decompilation. It prevents gentlemen but not villains. The overall encryption protection flow chart is shown in the figure below. Maven plug-in encryption uses custom maven plug-in to compile. The class file specified is encrypted, and the encrypted class file is copied to the specified path. Here, it is saved to resource/corecla.

See all articles