热搜:NVER node 开发 php

smarty生成静态页问题,值得思考?

2024-09-05 09:55:01
smarty生成静态页问题,值得思考?

我现在想使用smarty生成列表页,是真静态的。
如:
分类:新闻
共有50条数据。
一个列表页为10条数据。
共有5个分页。

如dedecms生成栏目页一样。
请教下大牛们,如何实现?劳烦写个小例子。


回复讨论(解决方案)

php 怎么做,smarty 还是一样的没啥区别

把生成的内容5个页要做成一定格式的页面,应该需要在smarty中专门写个方法

http://bbs.php100.com/read-htm-tid-308311.html

版主发的链接,代码不具体,模板也不好实现。

难点在于,
列表页模板如何写?
后台程序,如何分页生成不同的页面,调用不同的文章。

我已经做成功了,分享代码给大家,希望以后有人用得着。

public function tplmakelist(&$tpl){			$pageSize=1;			$_field=array('a.id','a.title','b.typedir','b.templist','b.keywords','b.description');			$this->_tables=array(DB_FREFIX.'article a',DB_FREFIX.'article_category b');			$data=parent::select($_field,array('where'=>array("a.catid=b.id AND b.id={$this->_R['typeid']}")));			$total=count($data);//分类下的所有文章			$pageTotal=ceil($total/$pageSize);//共有多少个分页			$tpl->template_dir=SMARTY_TEMPLATE_DIR;			for ($i=1;$i<=$pageTotal;$i++){//生成的页数				$file_name=ROOT_PATH.$data[0]->typedir."/list_{$this->_R['typeid']}_$i.html";				$this->_tables=array(DB_FREFIX.'article a',DB_FREFIX.'article_category b');				$firstPage = ($i-1)*$pageSize;				$datas=parent::select($_field,array('where'=>array("a.catid=b.id AND b.id={$this->_R['typeid']}"),'limit'=>"$firstPage,$pageSize"));				$tpl->assign('findlist',$data[0]);				$tpl->assign('pagelist',$datas);				$content=$tpl->fetch($data[0]->templist);				$this->MakeHtmlFile($file_name, $content);			}	}	private function MakeHtmlFile($file_name, $content)     {     //目录不存在就创建         if (!file_exists (dirname($file_name))) {              if (!@mkdir (dirname($file_name), 0777)) {                      die($file_name."目录创建失败!");              }          }     if(!$fp = fopen($file_name, "w")){              echo "文件打开失败!";              return false;          }          if(!fwrite($fp, $content)){              echo "文件写入失败!";             fclose($fp);              return false;          }      fclose($fp);       chmod($file_name,0666);      }


{foreach from=$pagelist item=list}{$list->title}{/foreach}

以后如果你要用的话,把数据库的字段换下,连接数据库根据你自己的引擎来写,当然还有待扩展,刚写完的。