Home > Backend Development > PHP Tutorial > destoon official tag list_PHP tutorial

destoon official tag list_PHP tutorial

WBOY
Release: 2016-07-13 10:24:21
Original
1344 people have browsed it

What is a tag call?

Tag calling is to read the number of calls (pagesize) from the data table (table) according to the calling condition (condition), sort it by the sorting method (order), and finally output the data through the layout of the tag template.
It can be seen that the work of the label is divided into two parts, one is to read the data, and the other is to display the data.
Tag function prototype

The tag function is stored in include/tag.func.php
tag($parameter, $expires = 0)
$parameter represents the string passed to the tag function, and the system automatically converts it into multiple variables
For example, pass table=destoon&pagesize=10&hello=world
The system is equivalent to getting
$table = ‘destoon’;
$pagesize = 10;
$hello = ‘world’;
Three variables
$expires represents the tag cache expiration time>0 caches $expires seconds; 0 - system default tag cache time; -1 - no cache; -2 - cache SQL results;
In general, keep the default value and do not need to pass it.


Data reading process

For example, the following tag:

<!–{tag(“table=sell&condition=status=3&order=addtime desc&pagesize=10″)}–>
Copy after login

will be converted into the following SQL statement:

SELECT *
FROM destoon_sell
WHERE status=3
ORDER BY addtime DESC
LIMIT 0,10
Copy after login

The read data will be saved in the $tags array
Data display process

1. Display through label template
Pass &template=abc to the tag function, for example:

<!–{tag(“table=…&template=abc”)}–>
Copy after login

The default tag template is saved in the template directory/tag/ directory. For example, &template=abc will call the template directory/tag/abc.htm template to display data
If the label template is placed in another directory, such as def, pass &dir=def&template=abc, and the system will call the template directory /def/abc.htm template

2. Loop data directly in the template

<!–{php $tags=tag(“table=…&template=null”);}–>
Copy after login


This way of writing passes the tag template as null, and directly returns the data to the $tags array. At this time, you can directly loop in the template
Here is a complete example:

<!–{php $tags=tag(“table=…&template=null”);}–>
{loop $tags $t}
…
{/loop>
Copy after login

The first way of writing is generally used for data that is called multiple times, and the second way of writing is generally used for data that is called only once.
Commonly used parameters and their meanings

moduleid
Moduleid refers to the module ID, which can be queried in the background module management. For data that directly calls the module, after setting the correct module ID, there is no need to pass the table parameter, and the system will automatically obtain it.
For example, if moduleid=5 is passed, the system will recognize it as calling supply information and automatically set the table parameter to sell

table
table refers to the table name, which can be queried in the background database maintenance. For Destoon system tables, there is no need to add a table prefix; for non-Destoon system tables, you need to fill in the complete table name and pass the prefix parameter
For example, for the Destoon system table, pass table=sell. If the table prefix is ​​destoon_, the system will recognize the table name as destoon_sell
For non-Destoon system tables, pass table=tb_abc&prefix= or table=abc&prefix=tb_, the system will recognize the table name as tb_abc

fields
fields refers to the query fields, the default is *. You can pass fields=title,addtime, for example, but generally there is no need to pass it. Destoon's unique tag caching mechanism will automatically cache the query results, so you don't have to worry about efficiency issues.

condition
Condition refers to the condition of the query. If not passed, it is 1, representing data of any condition (this requires understanding of SQL syntax). All Destoon modules are developed according to unified standards, so many conditions are common.
For example, status=3 indicates information that passed normally, status=3 and level=1 indicates information with level 1, status=3 and thumb<>” indicates information with a title picture, etc.

order
Order refers to the sorting method of data (this requires understanding of SQL syntax).
For example, order=addtime desc means to sort by adding time in descending order, order=itemid desc means to sort by itemid in descending order, order=rand() means random data, etc.

pagesize
pagesize refers to the number of calling data. If not passed, the default is 10.

template
template refers to the specified tag template. If not passed, the default is list, located in the template directory/tag/list.htm. If passed as null, it means that the tag template is not applied. See the above data display process.
Other common usage examples

Multiple table joint query
For example, to query the member and company information of the member named destoon, you can use:

{tag(“table=destoon_member m,destoon_company c&prefix=”&condition=m.userid=c.userid and m.username='destoon'&template=list-com”)}
Copy after login

destoon_member和destoon_company是表的实际名称(包含表前缀),prefix=”表示系统不再自动在表名前加前缀

控制标题长度
在标签里传递length参数,例如&length=20表示20个字符长度(一个汉字占2个字符),一般情况建议用css隐藏多余字符(定义height和overflow:hidden)
传递length参数,系统仅对title字段自动截取,如果需要截取其他字段,可用dsubstr函数
例如 {dsubstr($t[company], 20, ‘…')} 表示截取company字段为20个字符,截取后,结尾追加…

设置日期显示格式
可以在标签里传递datetype参数:
1 表示 年;
2 表示 月-日;
3 表示 年-月-日;
4 表示 月-日 时:分;
5 表示 年-月-日 时:分;
6 表示 年-月-日 时:分:秒
也可以在模板里直接使用date函数,例如{date(‘Y-m-d', $t[addtime])} 表示将时间转换为 年-月-日 格式

调用某一分类的信息
在标签里传递catid参数,例如&catid=5表示调用分类ID为5的所有信息。
如果调用多个分类,用逗号分隔分类ID,例如 &catid=5,6,7表示调用分类ID为5、6、7的所有信息。
分类调用默认包含子分类的信息,如果不需要包含子分类,可设置&child=0参数。
例如&catid=5&child=0表示只调用分类ID为5的信息,不包括子分类的信息。

调用某一地区的信息
调用地区信息和上述调用分类信息的方法完全相同,将其中的catid换为areaid即可。

显示信息所在分类

<a href=”{$MODULE[$moduleid][linkurl]}{$CATEGORY[$t[catid]][linkurl]}”>{$CATEGORY[$t[catid]][catname]}</a>
Copy after login

控制列数
此项常用于图片的布局,可使用cols参数。
例如调用12张图片,一行显示4个,共3行,则传递&pagesize=12&cols=4
支持cols参数的标签模板限thumb-table.htm和list-table.htm
其中,thumb-table.htm显示图片列表,list-table.htm显示文字列表
如果新建支持cols的标签模板或直接循环$tags,可参考以上两个模板的写法
上述效果可以也可以通过CSS实现,无需使用表格,请自行书写

显示文章的简介
使用{$t[introduce]}变量,如果要截取字数,例如80字符,可使用{dsubstr($t[introduce], 80, ‘…')}

函数原型
tag($parameter, $expires = 0)
$parameter 表示传递给tag函数的字符串,系统自动将其转换为多个变量
例如传递 table=destoon&pagesize=10,系统相当于得到$table = ‘destoon';$pagesize = 10;两个变量
$expires 表示缓存过期时间
>0 缓存$expires秒;0 – 系统默认时间;-1 – 不缓存;-2 – 缓存SQL;一般情况保持默认即可。

常量
{DT_SKIN}
系统风格网址。
{DT_PATH}
网站首页网址。

变量
$tags
以数组类型保存标签调用的数据,可通过loop语法遍历显示。
$pages
保存数据分页代码,仅在调用了分页时有效。
$MODULE[5][name]
ID为5的模块名称。
$MODULE[5][linkurl]
ID为5的模块网址。
$CATEGORY[5][catname]
ID为5的分类名称(仅变量$CATEGORY存在时有效)。
$CATEGORY[5][linkurl]
ID为5的分类网址(仅变量$CATEGORY存在时有效)。

常用字段
title 标题; linkurl 链接; catid 分类ID; introduce 简介; addtime 添加时间; 常用函数 dsubstr($string, $length, $suffix = ”)
将字符串$string截取为$length长,尾部追加$suffix(例如..)
date($format, $timestamp)
将时间戳$timestamp转化为$format(例如Y-m-d)格式

标签模板
模板保存于./template/default/tag/目录;
建议不要删除或者修改自带的模板,推荐在自带模板基础上新建模板并应用。

1.标签格式的大致说明

<!–{tag(“moduleid=9&table=article_9&length=40&condition=status=3&pagesize=10&datetype=2&order=addtime desc&target=_blank”)}–>
Copy after login

moduleid=9是资讯模块ID, 模块ID去模块管理查看;
article是资讯模块目录名;
&length=40是标签截取字数
&pagesize=10是调用条数
&datetype=2是显示时间添加时间

2.调用最新加入企业

<!–{tag(“moduleid=4&table=company&condition=groupid>4&pagesize=10&order=userid desc&template=list-com”)}–>
Copy after login

3.如何调用其中一个企业会员的供求信息及资讯
在condition=里加 and username='xxx'? xxx为会员登录名

4.如何调用 供应 求购 产品 下的 某个分类
调用分类下的信息可以设置 &catid=行业id&child=1 child=1表示同时调用下属的行业

5.调用二级栏目信息列表

<!–{tag(“moduleid=$moduleid&table=article_$moduleid&catid=$catid&child=1
&condition=status=3&order=”.$MOD[order].”&pagesize=6&datetype=2&target=_blank”)}–>
Copy after login

如果你是在文章模块里调用 可以用上面的代码 $catid 改为你要调用的栏目id即可
如果需要同时调用栏目下的信息 child=1即可 否则 child=0
如果是在网站其他地方调用,可以用下面的代码:

<!–{tag(“moduleid=9&table=article_9&catid=$catid&child=1&condition=status=3&order=addtime desc&pagesize=6&datetype=2&target=_blank”)}–>
Copy after login
Copy after login

注意moduleid的值要与你调用的模块id保持一致
补充:
下面这个在首页调用成功

<!–{tag(“moduleid=9&table=article_9&catid=$catid&child=1&condition=status=3&order=addtime desc&pagesize=6&datetype=2&target=_blank”)}–>
Copy after login
Copy after login

但是我想要资讯页内部的模版列表,也就是每条只显示22个字。

6.首页资讯栏目这里怎么调用
“9”为你模块的ID

{php $C = get_maincat(0, cache_read(‘category-9.php'));}
{loop $C $k $v}
<a href=”{$MODULE[9][linkurl]}{$v[linkurl]}”>{$v[catname]}</a>
{/loop}
Copy after login


7.公司列表 不能控制字数!!
你可以直接修改 list-com.htm
{$t[company]} 为 {dsubstr($t[company], $length)}

8.TAG常用标签
{$CATEGORY[$t[catid]]["catname"]} 所属栏目名称; {timetodate($t["addtime"], $datetype)}? 发布时间

9.其他
你可以通过&template= 来指定标签模版
如果没用这个参数 默认是list
位于模版目录tag目录
资讯 级别level 1级为 推荐文章 ;2级为 幻灯图片;3级为 推荐图文;4级为 头条文章;5级为 头条相关

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/825491.htmlTechArticle什么是标签调用? 标签调用是根据调用条件(condition)从数据表(table)读取调用数量(pagesize)条数据,并按排序方式(order)排序,最终通过标签模...
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