phpcms ajax列表分页加载更多

来自:互联网
时间:2019-02-22
阅读:
免费资源网 - https://freexyz.cn/

phpcms列表分页ajax加载更多如何实现呢?

1、在  /phpcms/modules/模块下加多一个ajaxlist文件夹,在其文件夹下新建一个index.php,内容如下:

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下新建ajax_list.html

<div id="ajax_list" >   
{pc:content action="lists" catid="10" order="id DESC" thumb="" moreinfo="1" }   
{loop $data $n $r}   
<li><a href="{$r['url']}" title="{$r['title']}">{$r['title']}</a></li>   
{/loop}   
{/pc}   
</div>   
<div class="pager 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?a=homeajaxlist&page="+_page,   
                    function(){   
                                //这个是让页面滚动到列表上方   
                                $("html,body").animate({scrollTop:$("#conter").offset().top},1000);   
                           
                    });   
            });           
    });   
</script>

3、然后在模板需要显示列表ajax的地方插入如下代码

<div id="conter" >   
       <div class="contain_ajaxhtmllist" >   
           {template "content","ajax_list"}          
      </div>   
</div>

未经验证,请在本地测试后方可正式应用于站点。

免费资源网 - https://freexyz.cn/
返回顶部
顶部