Home >Backend Development >PHP Tutorial >Empire CMS list template list.var supports program code, cmslist.var_PHP tutorial
1. When adding a template, the list.var template needs to check the "Use program code" option. As shown in the picture:
2. Add PHP code directly without adding c591142d12d44772f043be014d650196 program start and end tags.
3. The field value array variable is $r, and the corresponding field variable is $r[field name]. For example: the title field variable is $r[title]. In addition, the number variable is $no
4. Assign the final template content to the $listtemp variable.
list.var template example:
Example 1: Display the specified image if the information does not set a title image.
<span>1</span> <span>if(empty($r[titlepic])) </span><span>2</span> <span>{ </span><span>3</span> <span> $r[titlepic]='/images/img.gif'; </span><span>4</span> <span>} </span><span>5</span> $listtemp='<span><</span><span>li</span><span>><</span><span>a </span><span>href</span><span>="[!--titleurl--]"</span><span>><</span><span>img </span><span>src</span><span>="[!--titlepic--]"</span><span>></</span><span>a</span><span>></</span><span>li</span><span>></span>';
Explanation: $r[titlepic] is the title picture field variable. $listtemp is the template content variable.
Example 2: If the information was released today, display the "NEW" image logo.
<span>1</span> <span>$newimg=''; </span><span>2</span> if(time()-$r[newstime]<span><</span><span>=1</span><span>*24*3600) </span><span>3</span> <span>{ </span><span>4</span> <span> $newimg</span><span>='<img </span><span>src</span><span>="NEW图片地址"</span><span> border</span><span>="0"</span><span>></span><span>'; </span><span>5</span> <span>} </span><span>6</span> $listtemp='<span><</span><span>li</span><span>><</span><span>a </span><span>href</span><span>="[!--titleurl--]"</span><span>></span>[!--title--]<span></</span><span>a</span><span>></span> '.$newimg.'<span></</span><span>li</span><span>></span>';
Note: $r[newstime] is the release time field variable. $listtemp is the template content variable.
Example 3: Call the company name of the submitting user.
<span>1</span> <span>$userr=$empire->fetch1("select company from {$dbtbpre}enewsmemberadd where userid='$r[userid]' limit 1"); </span><span>2</span> $listtemp='<span><</span><span>li</span><span>><</span><span>a </span><span>href</span><span>="[!--titleurl--]"</span><span>></span>[!--title--]<span></</span><span>a</span><span>></span> <span><</span><span>span</span><span>></span>公司名称:'.$userr[company].'<span></</span><span>span</span><span>></</span><span>li</span><span>></span>';
Note: $r[userid] is the publisher user ID field variable. $listtemp is the template content variable.
Other instructions:
If $listtemp refers to the template content using single quotes, then use single quotes in front of it, for example: $listtemp='abd16c8c4b2fc95c2652a0ee599e0ad5';
On the contrary, if the template content is quoted using double quotes, then the double quotes must also be preceded by double quotes. , for example: $listtemp="91808d1bd4143a19436865f6591d6814";
supports program code to achieve a lot Very complex application requirements.