smarty 列表插件显示标题长度和连接
现在在写一个站, 要在smarty 插件那里写一个列表插件,要截取标题长度。
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><?php
function smarty_function_list($params, &$smarty)
{
extract($params);
$cate = !empty($cate) ? trim($cate) : '';//表名
$items = !empty($items) ? trim($items) : '*';//字段
$length=!empty($length) ? trim ($length) :'10';//长度
$where = !empty($where) ? trim($where) : '';//条件
$order = !empty($order) ? trim($order) : '';//排序
$page = !empty($page) ? intval($page) : 0;//分页
$pagesize = !empty($pagesize) ? intval($pagesize) : 20;
$varname = !empty($varname) ? trim($varname) : '';
global $db;
global $table;
$sql="select $items from ".$table[$cate];
if(!empty($where))
{
$sql.=" where $where ";
}
if(!empty($order))
{
$sql.=" order by $order";
}
$page=max($page,1);
if($pagesize<1)
{
$pagesize=10;
}
$rs=$db->PageExecute($sql,$pagesize,$page);
$rs=$rs->getRows();
$smarty->assign($length,$length);
$smarty->assign($varname, $rs);
unset($rs);
}
?>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
{--list cate="articles" items="Title" length=4 varname="rs"--}
{--foreach from=$rs item=r--}
{--$r.Title--}<br/>
{--/foreach--}
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号