##{foreach from=$new_articles item=article } : The beginning of the loop,
{/foreach} : The end of the loop ##$new_articles: For the things to be looped, here is the website News##{$article.short_title} : The tag
of the news title is in the pattern: {foreach from=$post item=name} content {/foreach}
{foreach from=$post item=name} and {/foreach} tags can add any content to be looped (can be anything), loop The number of times is limited by $post (I will tell you what to fill in here.) name is the object of the current cycle. Convenient to call data.
|
以后这个循环我们会经常的用到哦. 还是不懂也没有关系,每次遇到我都会讲哪里要怎么设置的,多用就会了。
我们也可以这么写哦 , 注意: 在代码编辑的视图里面编辑
1. <table> 2. {foreach from=$new_articles item=article} 3. <tr><td> 4. {$article.short_title} 5. </td></td> 6. {/foreach} 7. </table>
Copy after login
哈哈,保存,刷新首页看看,表格被一行一行的循环出来了哦
第二章
一人得道,鸡犬升天啊,谢谢ECshop将我提升为教程区版主 ,实在时荣幸啊,谢谢大家的支持, 谢谢我的笔记本电脑小Y,谢谢我的电脑桌,谢谢我的椅子,谢谢大家! 呵呵! ~Orz.
模板教程继续啦!
不知道大家是学会用循环了呢,还是我的言语实在有问题,大家实在无法完成阅读哦,居然大家都没有问题,暂时心里安慰,把他当做好事情,大家都会调用了,呵呵,那我们继续循环调用商品了!
好,继续在我们昨天的基础上,我们在网站快讯的循环后面,按 Enter键, 输入:商品列表,接着建立一个2行3列的表格,宽度为70%, 表格边框为1(为了让大家看清楚 ),起HTML代码如下
1. <p>商品列表</p> 2. <table width=”70%” border=”1″> 3. <tr> 4. <td>1</td> 5. <td>2</td> 6. <td>3</td> 7. </tr> 8. <tr> 9. <td>4</td> 10. <td>5</td> 11. <td>6</td> 12. </tr> 13. </table>
Copy after login
注: ( 1,2,3,4,5,6这些个是序号,方便跟大家讲解呢 )
在这里,我们暂时先把下面这一行去掉(为了大家操作简单),变成
1. <p>商品列表</p> 2. <table width=”70%” border=”1″> 3. <tr> 4. <td>1</td> 5. <td>2</td> 6. <td>3</td> 7. </tr> 8. </table>
Copy after login
我们要循环的是列,也就是
,因此我们的循环标签应该在 | 和 | 的外面, 而2,和3应该是循环出来的东西,也就时我模板里面只用保留 1 这个td就可以了,2 和3都要去掉,
于是就变成了下面的样子
1. <p>商品列表</p> 2. <table width=”70%” border=”1″> 3. <tr> 4. <td>1</td> 5. </tr> 6. </table>
Copy after login
好,现在我们开始加循环标签,我们要调用的是精品推荐商品, 代码如下:
1. <p>商品列表</p> 2. <table width=”70%” border=”1″> 3. <tr> 4. {foreach from=$best_goods item=goods} 5. <td>{$goods.short_style_name}</td> 6. {/foreach} 7. </tr> 8. </table>
Copy after login
注意了:foreach 表示下面的内容属于要进行循环,from=$best_goods 表示循环的内容来自$best_goods,($best_goods是精品商品推荐的标签 ) , item=goods 表示当前循环这一次的对象叫goods,你也可以改为其它的东东,当然{$goods.short_style_name}这个地方的goods也要相应的改了哦,{$goods.short_style_name} 表示goods 这个对象的商品名称. 好了,我们保存,前台刷新看一下啊。呵呵,精品商品被循环出来了吧?
接着,为了大家应用方便,我们把goods改为jingpinshangpin,代码如下:
1. <p>商品列表</p> 2. <table width=”70%” border=”1″> 3. <tr> 4. {foreach from=$best_goods item=jingpinshangpin} 5. <td>{$jingpinshangpin.short_style_name}</td> 6. {/foreach} 7. </tr>
Copy after login
好前台刷新看看哦,呵呵,夷?如果你有很多的精品商品你会发现商品变了,因为精品商品是随机调取出来的.
好我们继续完善他,给它加上链接对应商品的链接,也就是添加属性, 代码如下:
1. <p>商品列表</p> 2. <table width=”70%” border=”1″> 3. <tr> 4. {foreach from=$best_goods item=jingpinshangpin} 5. <td><a href=”{$jingpinshangpin.url}”>{$jingpinshangpin.short_style_name}</a></td> 6. {/foreach} 7. </tr> 8. </table>
Copy after login
刷新浏览器,点击链接看看链接到什么地方去了哦。呵呵! 链接到了每个产品自己的页面了呢。 说明:标签 {$jingpinshangpin.url} 就是精品商品的商品链接的标签了,但是要记得哦,$jingpinshangpin 是你起的名字哦,item=$jingpinshangpin的这个 $jingpinshangpin改变了的话,这里也要跟着改变。
接下来我们添加上商品的图片哦 ,也就是增加一个属性 ,代码如下:
1. <p>商品列表</p> 2. <table width=”70%” border=”1″> 3. <tr> 4. {foreach from=$best_goods item=jingpinshangpin} 5. <td><a href=”{$jingpinshangpin.url}”><img src=”{$jingpinshangpin.thumb}” border=”0″ /><br>{$jingpinshangpin.short_style_name}</a></td> 6. {/foreach} 7. </tr> 8. </table>
Copy after login
到前台刷新浏览器看看看,呵呵,商品缩略图也被调出来了。
说明:标签 {$jingpinshangpin.thumb} 就是精品商品的缩略图的标签了,但是要记得哦,$jingpinshangpin 是你起的名字哦,item=$jingpinshangpin的这个 $jingpinshangpin改变了的话,这里也要跟着改变。
如果你已经熟练理解和掌握了以上的步骤,那么下面就越来越清晰和容易了。
接下来我们调取新品上市(标签为: $new_goods )和热卖商品( 标签为:$hot_goods) ,接着在刚才的代码后面加上去就是了。我就不多讲了哦,代码如下
1. <p>新品上市</p> 2. <table width=”70%” border=”1″> 3. <tr> 4. {foreach from=$new_goods item=xinpinshangshi} 5. <td><a href=”{$xinpinshangshi.url}”><img src=”{$xinpinshangshi.thumb}” border=”0″ /><br> 6. {$xinpinshangshi.short_style_name}</a></td> 7. {/foreach} 8. </tr> 9. </table> 10. 11. <p>热卖商品</p> 12. <table width=”70%” border=”1″> 13. <tr> 14. {foreach from=$hot_goods item=remaishangpin} 15. <td><a href=”{$remaishangpin.url}”><img src=”{$remaishangpin.thumb}” border=”0″ /><br> 16. {$remaishangpin.short_style_name}</a></td> 17. {/foreach} 18. </tr> 19. </table>
Copy after login
接着我们要一个Menu菜单,也就是做一个产品的分类列表出来。相信你现在至少知道分类的标签是什么,就知道要怎么做了吧,呵呵.
分类的标签是:$categories
代码如下:
1. <p>分类列表</p> 2. {foreach from=$categories item=fenlei} 3. <a href=”{$fenlei.url}”>{$fenlei.name}</a> 4. {/foreach}
Copy after login
到前台刷新看看哦,呵呵,分类列表被调取出来了,我们试着在后台多添加几个一级分类,然后到首页刷新看看。
呵呵,我先去吃饭啦,吃完饭继续写如何把子分类调用出来,大家有问题多问哦,
吃饭回来了….(PS:这是怎么地啊,呵呵!)
子分类的标签是对应在父分类标签来调用的.代码如下:
1. <p>分类列表</p> 2. {foreach from=$categories item=fenlei} 3. <a href=”{$fenlei.url}”> {$fenlei.name}</a> 4. {foreach from=$fenlei.children item=child} 5. <br>- – <A href=”{$child.url}”>{$child.name|escape:html}</A> 6. {/foreach} 7. {/foreach}
Copy after login
保存以后前台刷新看看呢。呵呵,怎么样?子分类也被调用出来了吧,当然可以根据自己的需要,加上不同的表格或者图片的修饰哦,子分类是放在了父分类标签的基础上来调用的呢。
不过如果你的分类已经固定了很少改动,我建议还是做成死的,这样可以做的更漂亮一些,比如每个分类直接是用图片来代替。呵呵,我一般就是这么处理的,我除了商品和新闻是动态调用出来的以外,其它的都是做成固定的死的,这样就能够设计的很漂亮,因为有时候受到代码的限制,做出来不是很好看。(…说的好模糊,您能理解吗?不能的话就告诉我 ).
本来教程已经写了好多了,但是很多地方写的有点让新手不是那么容易接受,所以就一直在想办法,如何讲解的更简单一些,能让每个人都学会做模板。思考中…..
由于个人原因,今天教程停播一天,明天继续,实在不好意思各位. ~Orz.
啊,今天的章节就算是结束啦,明天预告:
1.如何调用某个分类里面的商品 2.如何制作商品展示页面的模板 3.完善前面讲的章节,并对大家提出的问题做出解答
今天我们来学习如何掉用某一个分类里面的产品。 首先把 default文件夹中的category.dwt 的名字改为category_bak.dwt,然后新建一个category.dwt文件. 然后插入下面的代码:
1. {foreach from=$goods_list item=goods} 2. <img src=”{$goods.goods_thumb}” border=”0″ /><br> 3. {$goods.goods_name} 4. {/foreach}
Copy after login
复制代码
注:$goods_list表示商品标签
接着我们访问这个页面:(Ecshop的访问网址/category.php?id=1)例如:http://localhost/ecshop/category.php?id=1 这样我们就访问到了分类id为1的商品了,我们也可以让id=2就访问到id = 2商品了,那如何看某个分类的id呢? 我们看后台: 商品管理-》商品分类-》就可以看到商品分类的列表,然后把鼠标指上去选择新窗口打开,就能在地址来里面看到goods.php?act=list&cat_id=1这样子的信息,cat_id所等于的值就是这个分类的id了,然后就可以拿来调取了,呵呵。
好每次每次都把商品的列表调取出来了,那么如何调取某一个商品的页面呢? 首先把 default文件夹中的goods.dwt 的名字改为goods_bak.dwt,然后新建一个goods.dwt文件. 然后插入下面的代码:
1. 商品图片: <img src=”{$goods.goods_img}” /><br><br> 2. 商品名称:{$goods.goods_style_name}<br><br> 3. 商品货号:{$goods.goods_sn}<br><br> 4. 商品品牌: {$goods.goods_brand}<br><br> 5. 商品数量:{$goods.goods_number} 单位:{$goods.measure_unit}<br><br> 6. 添加时间:{$goods.add_time}<br><br> 7. 市场价格:{$goods.market_price}<br><br> 8. 本店价格:{$goods.shop_price_formated}<br><br> 9. 注册用户价格:{$rank_price.price}<br><br> 10. 注册用户价格:{$rank_price.price}<br><br> 11. 注册用户价格:{$rank_price.price}<br><br>
Copy after login
复制代码
接着我们访问这个页面:(Ecshop的访问网址/goods.php?id=1)例如:http://localhost/ecshop/goods.php?id=1 这样我们就访问到了商品id为1的商品了,我们也可以让id=2就访问到id = 2商品了,那如何看某个商品的id呢?
我们看后台:商品管理-》商品列表-》就可以看到商品品的列表,最前面那一栏就是商品的id了,,然后就可以拿来调取了,呵呵。
还有人在问品牌的,某一个品牌的商品怎么调用,呵呵,下次有时间再讲 更新啦!!
今天我们学习一下如何在首页调取某个分类的商品: 注意了,这里的修改有一些麻烦了哦:
首先你需要下载一套新的模板,比如blueksy 上传到模板目录 /themes/ 也就是 /themes/bluesky,
然后进入网站后台->模板管理->模板选择,选择bluesky, 选择OK, 然后到网站后台 -> 模板管理 -> 设置模板 -> 分类下的商品 ( 点击分类下的商品前面的+号,然后选择“主区域中间“,序号默认, 商品分类随便选择一个就可以了”,
然后填写显示的条数,填写好后点击确定提交,( 注意: 有的朋友可能会遇到提交不了,是因为权限问题,需要把bluesky的模板权限改,然后再重新提交一次)。
这里我增加了两个,的数据是:主区域空间 0 手机 6
主区域空间 0 手机 6 我们在这里增加了多少条记录,对应首页就可以调取多少个分类。
好接下来我们恢复模板为原来我们改过的default模板
在我们以前做的基础上增加如下代码(也就是在原来代码的下面加上):
1. <p>第一个分类的<p> 2. <?php $this->assign(‘cat_goods’,$this->_var['cat_goods_1']); ?><?php $this->assign(‘goods_cat’,$this->_var['goods_cat_1']); ?><?php echo $this->fetch(‘library/cat_goods.lbi’); ?> 3. <p>第二个分类的<p> 4. <?php $this->assign(‘cat_goods’,$this->_var['cat_goods_3']); ?><?php $this->assign(‘goods_cat’,$this->_var['goods_cat_3']); ?><?php echo $this->fetch(‘library/cat_goods.lbi’); ?>
Copy after login
复制代码
这里要注意了, 红色的 1 代表你要显示分类的分类的ID, 将它改为你需要的 刚才添加的ID就可以了 红色的 3 代表你要显示分类的分类的ID, 将它改为你需要的 刚才添加的ID就可以了
好了,保存,前台刷新看看啊,呵呵.是不是我们要的分类就出来了,
看样子改起来很简单哦,不过每次都是这样要操作两个模板才能改还是有些麻烦,呵呵,等到高手进阶的时候再来讲怎么做。
仔细一看还是有点不好的地方哦,就是样子不好看啊,对不对?是默认模板的样子,没有关系啦,我们打开 librasy目录中的cat_goods.lbi文件修改就可以了。修改要注意的地方上门讲过了,不过这里还是要再说明一些小问题
cat_goods.lbi的代码如下:
1. <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″> 2. <p><img src=”../images/green_arrow.gif” width=”37″ height=”37″ alt=”" border=”0″ style=”vertical-align:middle” /><a href=”{$goods_cat.url}”>{$goods_cat.name|escape:html}</a></p> 3. <p> 4. <!–{foreach from=$cat_goods item=goods}–> 5. <table border=”0″ cellpadding=”3″ cellspacing=”1″ style=”float: left”> 6. <tr> 7. <td align=”center”><a href=”{$goods.url}”><img src=”{$goods.thumb}” border=”0″ alt=”{$goods.name|escape:html}” /></a></td> 8. </tr> 9. <tr> 10. <td><a href=”{$goods.url}” title=”{$goods.name|escape:html}”>{$goods.short_name|escape:html}</a><br /> 11. <!– {if $goods.promote_price neq “”} –> 12. {$lang.promote_price}<span>{$goods.promote_price}</span> 13. <!– {else}–> 14. {$lang.shop_price}<span>{$goods.shop_price}</span> 15. <!–{/if}–> 16. </td> 17. </tr> 18. </table> 19. <!–{/foreach}–> 20. <br style=”clear:both”/> 21. </p>
Copy after login
复制代码
Some strange thing here is that there are more symbols on both sides of the label. This does not matter. It does not matter if you delete it.
Name |
Type |
Remarks (function or meaning) |
File(Directory)Can the name be changed |
images |
Directory |
Directory for storing template images |
Cannot be changed |
library |
Directory |
Directory for storing template library files |
Cannot be changed |
screenshot.png |
Picture |
Used for"Backend management -> Template management -> Template Select ” to display the template thumbnail.
|
Unchangeable |
style.css |
cssStyle sheet |
|
Cannot be changed |
Remarks: Template There are a total of 22 files( format: .dwt). Reminder: 1, Changing the contents of the library file in the template file is invalid. When the page is refreshed, the program automatically reloads the contents of the library file into the template file(Subject to the content of the library file). 2, All id values starting with ECS_ in the template must be retained ( is related to ajax). 3, Non-library file content cannot be placed in the editable area, otherwise the non-library file content will be overwritten and deleted when setting the template. |
##brand.dwt
|
Template file
| ## Product brand page | cannot be changed |
article.dwt |
Template file |
Article content page |
Cannot be changed |
article_cat.dwt |
Template file |
Article list page |
Cannot be changed |
##catalog.dwt
|
Template file
|
All category pages
|
Cannot be changed
|
##category.dwt | Template file | Product list page | cannot be changed |
compare.dwt | Template file | Product comparison page | Cannot be changed |
flow.dwt
##Template file |
Shopping Cart and Shopping Process Page |
Cannot be changed |
gallery.dwt |
Template file |
Product album page |
Cannot be changed |
goods.dwt |
Template file |
Product details page |
Cannot be changed |
##group_buy_goods.dwt
|
Template file
|
Group purchase product details page
| ##Cannot be changed |
##group_buy_list.dwt
Template file |
Group purchase product list page |
Cannot be changed |
| ##index.dwt
Template file |
Homepage |
Cannot be changed |
message.dwt |
Template file |
Information prompt page |
Cannot be changed |
##pick_out.dwt
|
Template file
|
Shopping center page
|
Cannot be changed
|
receive.dwt
|
Template file
|
Receipt confirmation information page
|
Cannot be changed
|
##respond.dwt | Template file
| Online payment result prompt information page | Cannot be changed |
##search.dwt
Template file |
Product search page |
Cannot be changed |
snatch.dwt |
Template file |
Raiders of the Lost Ark page |
Cannot be changed |
tag_cloud.dwt |
Template file |
Tag cloud page |
Cannot be changed |
##user_clips.dwt
|
Template file
|
User center page (including: welcome page, my message, my tags, favorite products, out-of-stock registration list, add missing items Cargo registration.)
|
Cannot be changed
|
##user_passport.dwt | Template file | User security page (including: member login, member registration, password retrieval.) | Cannot be changed |
user_transaction.dwt | Template file | User center page (including: personal Information, my red envelope, add red envelope, my order, order details, merged order, order status, product list, total cost, consignee information, payment method, other information, member balance.) | Cannot be changed |
Remarks: There are 40 library files in total (Format .lbi) Reminder: Try to keep the default file name, otherwise the background management will not be able to manage the library file or there will be unforeseen errors. |
ad_position.lbi |
Library file |
Advertising position |
Unchangeable |
##bought_goods.lbi
|
Library file
|
What products have been purchased by people who have purchased this product
|
Cannot be changed
|
brand_goods.lbi
|
Library file
|
Brand’s goods
|
cannot be changed
|
brands.lbi
|
Library file
|
Brand area
|
Cannot be changed
|
##cart.lbi |
Library file |
Shopping cart |
Cannot be changed |
cat_articles.lbi |
Library file |
Article list |
Unchangeable |
##cat_goods.lbi
|
Library file
|
Category The items below
|
cannot be changed
|
category_tree.lbi
|
Library file
|
Product classification tree
|
Cannot be changed
|
comments .lbi
|
Library file
|
User comment list ( ajaxLoading comments_list.lbi library file.)
|
cannot be changed
|
##comments_list. lbi |
Library file |
User comment content |
cannot be changed |
consignee.lbi |
Library file |
Shipping address form |
Unchangeable
|
##goods_article.lbi
|
Library file
|
Related articles
|
Cannot be changed
|
##goods_attrlinked.lbi | Library file | Products associated with attributes | cannot be changed |
goods_fittings.lbi
##Library file |
Related accessories |
Cannot be changed |
|
goods_gallery.lbi
Gallery file |
Product Album |
Cannot be changed |
##goods_list.lbi
|
Library file
|
Product list
|
Cannot be changed
|
goods_related.lbi
|
Library file
|
Related goods
|
Not available Change
|
goods_tags.lbi
|
library file
|
goods tags
|
Cannot be changed
|
group_buy.lbi
|
Library file
|
Home page group purchase products
|
cannot be changed
|
help.lbi
|
Library file
|
Online store help
|
Cannot be changed
|
history.lbi |
Library file |
Product browsing history |
Unchangeable |
invoice_query.lbi |
Library file |
Invoice Query |
Cannot be changed |
##member.lbi
|
Library file
|
Member login (ajaxLoadingmember_info.lbi Library file.)
|
Cannot be changed
|
member_info. lbi
| ##Library file | Member login form and user account information after successful login | Not available Change |
new_articles.lbi
##Library file |
Latest articles |
Unchangeable |
order_total.lbi |
Library file |
Total order fee |
Cannot be changed |
##page_footer.lbi
|
Library file
|
Page footer
|
Cannot be changed
|
page_header.lbi
|
Library file
|
Top of page
|
Unchangeable
|
##pages.lbi | Library file | list Pagination | Unchangeable |
recommend_best.lbi | Library file | High Quality Recommendation | Cannot be changed |
recommend_hot.lbi |
Library file |
Hot-selling items |
Cannot be changed |
##recommend_new.lbi
|
Library file
|
New product recommendation
| ##Cannot be changed |
##recommend_promotion.lbi
Library file |
Promotion items |
Cannot be changed |
|
search_form.lbi
Library file |
Search form |
cannot be changed |
|
snatch.lbi
Library file |
Raiders of the Lost Ark Bidding Form (must be id="ECS_SNATCH"contains implementationajaxRefresh.) |
Cannot be changed |
snatch_price.lbi |
##Library file
|
Raiders of the Lost Ark latest bid list (must be id="ECS_PRICE_LIST"Contains the implementation of ajaxrefresh.)
|
Cannot be changed
|
##top10.lbi | Library file | Sales Ranking | Cannot be changed |
##ur_here.lbi
Library file |
Current location |
Cannot be changed |
|
user_menu.lbi
Library file |
User Center Menu |
Cannot be changed |
##vote.lbi
|
Library file
|
Online survey
|
Cannot be changed
|
ECSHOP Layout reference picture(Applicable versionv2.1.5)
Article list page : article_cat.dwt
Article content page: article.dwt
Product brand page: brand.dwt
All category pages: catalog.dwt
Product list page: category.dwt
Product comparison page: compare.dwt
Shopping cart and shopping process page: flow.dwt
Product album page: gallery.dwt
Product details page: goods.dwt
Group purchase product details page: group_buy_goods.dwt
Group purchase product list page: group_buy_list.dwt
Homepage: index.dwt
Message prompt page: message.dwt
Shopping center page : pick_out.dwt
Receive confirmation information page: receive.dwt
Online payment prompt information page: respond.dwt
Product search page: search.dwt
Raiders of the Lost Ark Page: snatch.dwt
tagcloud page: tag_cloud. dwt
User center page (including: welcome page, my message, my tags, favorite products, out-of-stock registration list, add out-of-stock registration.) : user_clips.dwt
User security page (including: member login, member registration, password retrieval.) : user_passport.dwt
User center page (including: personal information, my red envelope, add red envelope, my order, order details, merged order, order status, product list, cost Total, consignee information, payment method, other information, membership balance.) : user_transaction.dwt