生成新闻列表页如何替换分页?
发布于:2022-01-17 09:50:54
#1 helloniu
$urls = array();
$o = spClass("tbl_article");
$total = $o->findCount(array('classID'=>$classid));
$perpage = 30;
$pagenum = ceil($total/$perpage);
for($i = 1;$i <= $pagenum;$i++)
{
if ($i==1)
{array_push($urls,array(array("news", "index", array('id'=>$classid,'page'=>$i)),'/'.$class_name.'/index.html'));}
else
{array_push($urls,array(array("news", "index", array('id'=>$classid,'page'=>$i)),'/'.$class_name.'/index_'.$i.'.html'));}
}
spClass('spHtml')->makeAll($urls); // 使用makeAll来制作
echo "新闻中心二级栏目页生成完毕!
";
怎么替换分页 现在的分页还是那种动态方式的 用什么方法 谢谢了 一天问了挺多低级的问题 :handshake
2011-01-14 17:40:29
#2 jake
spHtml在分页方面要注意spUrl参数一致并匹配,上面的url的参数和分页的参数一样吗?
另外,你可以试试在上面代码中
array('id'=>$classid,'page'=>$i)
改成
array('id'=>(int)$classid,'page'=>(int)$i)
或者
array('id'=>(string)$classid,'page'=>(string)$i)
来试试
2011-01-14 19:48:09
#3 helloniu
$class_id=$this->spArgs("class_id");
$sp = spClass("tbl_articleclass");
$sql="select pinyinname from `tbl_articleclass` where id = $class_id";
$result = $sp->findSql($sql);
foreach($result as $value)
{
$class_name=$value['pinyinname'];
}
$urls = array();
$o = spClass("tbl_article");
$total = $o->findCount(array('classID'=>$class_id));
$perpage = 30;
$pagenum = ceil($total/$perpage);
for($i = 1;$i <= $pagenum;$i++)
{
if ($i==1)
{array_push($urls,array(array("news", "index", array('class_id'=>(int)$class_id,'page'=>(int)$i)),'/'.$class_name.'/index.html'));}
else
{array_push($urls,array(array("news", "index", array('class_id'=>(int)$class_id,'page'=>(int)$i)),'/'.$class_name.'/index_'.$i.'.html'));}
}
spClass('spHtml')->makeAll($urls); // 使用makeAll来制作
echo "栏目页生成成功!
";
最新的
动态访问地址 news.php?c=news&a=index&class_id=9
生成新闻列表页地址 news.php?c=html&a=news_html&class_id=9 代码在上面
为什么 列表页生成成功了 下面的链接没有变成想应的index_2.html index_3.html... 还是之前的动态地址呢?
2011-01-15 15:06:42
#4 helloniu
<{if $pager}>
共有<{$pager.total_count}>条,共有<{$pager.total_page}>页(每页<{$pager.page_size}>条):
<{if $pager.current_page != $pager.first_page}>
<< 上一页 <{else}>
<< 上一页 <{/if}>
<{foreach from=$pager.all_pages item=thepage}>
<{if $thepage != $pager.current_page}>
<{$thepage}> <{else}>
<{$thepage}> <{/if}>
<{/foreach}>
<{if $pager.current_page != $pager.last_page}>
下一页 >> <{else}>
下一页 >> <{/if}>
<{/if}>
模板页的分页代码
2011-01-15 15:09:36
#5 helloniu
1595100469s:346:"news|index|{"class_id":"26","page":"1"}||//chanjingxinwen/index.html|E:\wwwroot/news///chanjingxinwen/index.html
news|index|{"class_id":"26","page":"2"}||//chanjingxinwen/index_2.html|E:\wwwroot/news///chanjingxinwen/index_2.html
news|index|{"class_id":"26","page":"3"}||//chanjingxinwen/index_3.html|E:\wwwroot/news///chanjingxinwen/index_3.html";
生成的缓存文件
2011-01-15 22:10:07
#6 jake
配置
'html' => array(
'enabled' => TRUE,
),
开启另外,页码循环的时候 $i 要加上 (int)$i
2011-01-16 10:15:45
#7 helloniu
配置肯定没问题 页码循环也已经是(int)$i 仍然没有变化
2011-01-17 09:28:16
#8 jake
配置肯定没问题 页码循环也已经是(int)$i 仍然没有变化
helloniu 发表于 2011-1-17 09:28 
看看我这里的例子:
myhtml2.zip
2011-01-17 12:12:44
#9 helloniu
刚下载测试
$o = spClass("tbl_article");
$total = $o->findCount(array('classID'=>$classid));
问题出在这里 只要加上这个条件就会分页错误 请问jake有什么解决方法吗?
2011-01-17 14:08:11
#10 jake
加上(int)好像没问题
2011-01-17 16:22:47
#11 helloniu
class main extends spController
{
function index(){
$type=$this->spArgs("type");
$count = spClass("guestbook");
$count = $count->findCount(array('type'=>(int)$type));
$urls = array();
for($i = 1;$i <= ceil($count/2);$i++)
{
$urls[] = array(
array('main', 'show', array('type'=>(int)$type,'page'=>(int)$i))
);
}
spClass('spHtml')->makeAll($urls);
}
function show(){
$this->data = spClass('guestbook')->spPager($this->spArgs('page',1), 2)->findAll();
$this->pager = spClass('guestbook')->spPager()->getPager();
$this->display('main_show.html');
}
}
仍然没变化 还是动态地址 生成页面没问题 数据库我加了type字段了 int格式
2011-01-17 17:23:56
#12 jake
class main extends spController
{
function index(){
$classid=$this->spArgs("classid", 1);
$count = spClass("guestbook");
$count = $count->findCount();
$urls = array();
for($i = 1;$i <= ceil($count/2);$i++)
{
$urls[] = array(
array('main', 'show', array('classid'=>(string)$classid,'page'=>(int)$i))
);
}
spClass('spHtml')->makeAll($urls);
}
function show(){
$this->classid = (string)$this->spArgs('classid');
$this->data = spClass('guestbook')->spPager($this->spArgs('page',1), 2)->findAll();
$this->pager = spClass('guestbook')->spPager()->getPager();
$this->display('main_show.html');
}
}
加string类型,强制限定一下。
2011-01-17 17:55:45
#13 helloniu
按照你的代码 还是一样 仍然是动态 只要不加where条件就没问题
附数据库内容
2011-01-27 11:07:04
#14 jake
不是(string)就是(int)
2011-01-29 18:27:00