应用phpcms时遇到的问题及smarty标签的应用

1、循环语句{loop $data $n $r} {/loop}

//php对应源代码
<?php $data = subcat($module, $catid);?>
<?php } ?>

【具体实例】

标签模板获取当前栏目名及提取栏目下的新闻
{loop $data $n $r}
{
if $n == 1}
<h3><a href="{$CATEGORY[$r[catid]][url]}">{$CATEGORY[$r[catid]][catname]}</a></h3>
<dl>
<dt><a href="{$r[url]}" target="{$target}"><img src="{thumb($r[thumb], $width, $height)}" alt="{$r[title]}" width="{$width}" height="{$height}"/></a></dt>
<dd><a href="#"><a href="{$r[url]}" target="{$target}" title="{$r[title]}">{str_cut($r[title], $titlelen1,'')}</a></a></dd>
</dl>
<ul id="aRightList">
{
else}
<li><a href="{$r[url]}" target="_bank" title="{$r[title]}">&bull;{str_cut($r[title],$titlelen2,'')}</a></li>
{
/if}
{
/loop}
</ul>

2、get循环语句{get sql="" rows=""}{/get}

//php对应源代码
<?php $DATA = get("sql语句", 0, 0, "", "");if(is_array($DATA)){ foreach($DATA AS $n => $r) { $n++;?>
<?php } } unset($DATA); ?>

【具体实例】

{get sql="SELECT * FROM `xw_special_content` AS a, `xw_content` AS b WHERE a.contentid = b.contentid AND a.specialid =$specialid ORDER BY b.contentid DESC" rows="15" }
//内容
{/get}

3、条件语句{if}{elseif}{else}{/if}

【具体实例】

通过判断设置前3调新闻数据不一样的样式
{if $n < 4}
<h2><a href="{$r[url]}" target="_blank" title="{$r[title]}">{str_cut($r[title],48,'')}</a></h2>
{
elseif $n == 4}
<ul class="fix">
<li>&bull;<a href="{$r[url]}" target="_blank" title="{$r[title]}">{str_cut($r[title],48,'')}</a></li>
{
else}
<li>&bull;<a href="{$r[url]}" target="_blank" title="{$r[title]}">{str_cut($r[title],48,'')}</a></li>
{
/if}

4、经常用到的sql语句

【循环提取栏目】:

select * from xw_category where parentid=32 and ismenu!='0' order by listorder asc

【循环提取某个栏目id=132下从第3条到第6条的新闻内容】:

select * from xw_content where catid=132 order by updatetime asc limit 3,6

【循环最热新闻(按点击率排行)】:

select c.contentid,c.catid,c.typeid,c.areaid,c.title,c.style,c.thumb,c.keywords,c.description,c.userid,c.updatetime,c.inputtime,c.url,n.hits form `phpcms_content` c,`phpcms_content_count` n where c.contentid=n.contentid and c.`status`=99 ".get_sql_catid(31)." order by n.hits desc

5、常用的数据语句

【文字链接】:

<a href="{$r[url]}" title="{$r[title]}">{str_cut($r[title], 40,'')}</a>

{str_cut($r[title], 40,'..')}: 第二次参数为截取的文字字节长度也就是可以写20个汉字,第三个参数为省略后的内容,不写者没有。

【缩略图链接】:

<a href="{$r[url]}"><img src="{thumb($r[thumb], 450, 351)}" alt="{$r[title]}" /></a>

{thumb($r[thumb], 450, 351)}第一个参数为基本图片数据,后两个参数为将要裁 剪的图片width和height,都是按等比例裁剪

【文章描述】:

<a href="{$CATEGORY[$r[catid]][url]}">[{$CATEGORY[$r[catid]][catname]}]</a>

{str_cut(strip_tags($r[description]),450)}第一个参数为基本数据,第二个参数为截取的长度值

【文章栏目名】:

<a href="{$CATEGORY[$r[catid]][url]}">[{$CATEGORY[$r[catid]][catname]}]</a>

6、一定用到的帮助文档及数据字典

PHPCMS2008 开发文档

posted @ 2010-06-03 19:04  chesihui  阅读(572)  评论(0编辑  收藏  举报