phpcms列表页ajax分页效果:
1、在 /phpcms/modules/模块下加多一个ajaxlist文件夹,在其文件夹下新建一个index.php,内容如下:
<?php defined(‘IN_PHPCMS‘) or exit(‘No permission resources.‘); //模型缓存路径 define(‘CACHE_MODEL_PATH‘,CACHE_PATH.‘caches_model‘.DIRECTORY_SEPARATOR.‘caches_data‘.DIRECTORY_SEPARATOR); pc_base::load_app_func(‘util‘,‘content‘); class index { private $db; function __construct() { $this->db = pc_base::load_model(‘content_model‘); $this->_userid = param::get_cookie(‘_userid‘); $this->_username = param::get_cookie(‘_username‘); $this->_groupid = param::get_cookie(‘_groupid‘); } public function homeajaxlist() { if(isset($_GET[‘siteid‘])) { $siteid = intval($_GET[‘siteid‘]); } else { $siteid = 1; } $page = $_GET[‘page‘]?$_GET[‘page‘]:1; $siteid = $GLOBALS[‘siteid‘] = max($siteid,1); define(‘SITEID‘, $siteid); $_userid = $this->_userid; $_username = $this->_username; $_groupid = $this->_groupid; //SEO $SEO = seo($siteid); $sitelist = getcache(‘sitelist‘,‘commons‘); $default_style = $sitelist[$siteid][‘default_style‘]; $CATEGORYS = getcache(‘category_content_‘.$siteid,‘commons‘); include template(‘content‘,‘list_ajax‘,$default_style); } } ?>
2、在 /phpcms/templates/default/content下新建list_ajax.html
<div id="ajax_list" > {pc:content action="lists" catid="7" order="id DESC" thumb="" moreinfo="1" page="$page"} {loop $data $r} <li><a href="{$r[‘url‘]}" title="{$r[‘title‘]}">{$r[‘title‘]}</a></li> {/loop} {/pc} </div> <div class="ajaxhomelist"> {$pages} </div> <script type="text/javascript"> $(function(){ var curr_page = parseInt($(‘.ajaxhomelist span‘).text()); $(‘.ajaxhomelist a‘).click(function(event){ event.preventDefault(); _page = $(this).text(); if(_page == "下一页") _page = curr_page+1; if(_page == "上一页") _page = curr_page-1; $(‘.contain_ajaxhomelist‘).load( "{siteurl($siteid)}/index.php?m=ajaxlist&c=index&a=homeajaxlist&page="+_page, function(){ //这个是让页面滚动到列表上方 $("html,body").animate({scrollTop:$("#conter").offset().top},1000); }); }); }); </script>
3、然后在模板需要显示列表ajax的地方插入如下代码
<div class="col-left"> <div class="crumbs"><a href="{siteurl($siteid)}">首页</a><span> > </span>{catpos($catid)} 列表</div> <div id="conter" > <div class="contain_ajaxhomelist" > {template "content","list_ajax"} </div> </div> </div>
下面来看一下ajax分页效果:
是不是后面的 &page=1 ,&page=2 不见了,列表ajax分页成功。
本文出自 “Jack_phpcms” 博客,请务必保留此出处http://maifang158.blog.51cto.com/5433990/1962655
原文地址:http://maifang158.blog.51cto.com/5433990/1962655