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 and ?> 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=''[!--titlepic--]'>';
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=""[!--titlepic--]">";
supports program code to achieve a lot Very complex application requirements.