search
Homephp教程php手册帝国CMS 列表模板list.var支持程序代码,cmslist.var

帝国CMS 列表模板list.var支持程序代码,cmslist.var

1、增加模板时list.var模板需要勾选“使用程序代码”选项。如图:

2、直接添加PHP代码,不需要加程序开始和结束标记。

3、字段值数组变量为$r,对应的字段变量为$r[字段名],如:标题字段变量就是$r[title]。另外编号变量为$no

4、将最终模板内容赋给$listtemp变量。

 

list.var模板范例:
例子1:如果信息没有设置标题图片就显示指定的图片。

<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>';

说明:$r[titlepic]为标题图片字段变量。$listtemp为模板内容变量。

 

例子2:如果信息是今天发布的就显示“NEW”图片标识。

<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 alt="帝国CMS  列表模板list.var支持程序代码,cmslist.var" ><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>';

说明:$r[newstime]为发布时间字段变量。$listtemp为模板内容变量。

 

例子3:调用投稿用户的公司名称。

<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>';

说明:$r[userid]为发布者用户ID字段变量。$listtemp为模板内容变量。

其他说明:
如果$listtemp引用模板内容是用单引号,那么里面使用单引号前面要加\,例如:$listtemp='帝国CMS  列表模板list.var支持程序代码,cmslist.var\'[!--titlepic--]\'>';
相反如果引用模板内容是用双引号,那么里面使用双引号前面也要加\,例如:$listtemp="帝国CMS  列表模板list.var支持程序代码,cmslist.var\"[!--titlepic--]\">";

支持程序代码可以实现很多非常复杂的应用需求。

 

Statement
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 Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),