phpcms v9 wap手机门户站点内容页添加上一篇、下一篇的方法

PHP源码修改:打开 phpcms modules wap index php 文件找到if(!$r || $r[ status ] != 99) showm

PHP源码修改:
打开 phpcms\modules\wap\index.php 文件
找到
if(!$r || $r['status'] != 99) showmessage(L('info_does_not_exists'),'blank');
在其下面添加
//上一篇
$previous_page = $this->db->get_one("`catid` = '$catid' AND `id`<'$id' AND `status`=99",'*','id DESC');
//下一篇
$next_page = $this->db->get_one("`catid`= '$catid' AND `id`>'$id' AND `status`=99");
//当前页为第一篇时:再点击上一篇仍然显示第一篇
if(empty($previous_page)) {
$previous_page = $this->db->get_one("`catid` = '$catid' AND `id`='$id' AND `status`=99",'*','id DESC');
}
//当前页为最后一篇时:再点击下一篇仍然显示最后一篇
if(empty($next_page)) {
$next_page = $this->db->get_one("`catid`= '$catid' AND `id`='$id' AND `status`=99");
}

 

 

使用排序的上一篇下一篇解决办法

$listorder = $r['listorder'];
//上一篇
$previous_page = $this->db->get_one("`catid` = '$catid' AND `listorder`<'$listorder' AND `status`=99",'*','listorder desc');
//下一篇
$next_page = $this->db->get_one("`catid`= '$catid' AND `listorder`>'$listorder' AND `status`=99",'*','listorder asc');
//当前页为第一篇时:再点击上一篇仍然显示第一篇
if(empty($previous_page)) {
$previous_page = $this->db->get_one("`catid` = '$catid' AND `listorder`='$listorder' AND `status`=99",'*','listorder desc');
}
//当前页为最后一篇时:再点击下一篇仍然显示最后一篇
if(empty($next_page)) {
$next_page = $this->db->get_one("`catid`= '$catid' AND `listorder`='$listorder' AND `status`=99",'*','listorder asc');
}


模板调用:
<a href="{WAP_SITEURL}&a=show&catid={$catid}&typeid=1&id= {$previous_page[id]}">上一篇:{$previous_page[title]}</a>
<a href="{WAP_SITEURL}&a=show&catid={$catid}&typeid=1&id= {$next_page[id]}">上一篇:{$next_page[title]}</a>

标签: