(dedecms)实现加载更多功能

php代码部分:

///////////////////dedecms  目录下创建 more.php 文件///////////////////////////
///首页显示更多php代码
require_once(dirname(__FILE__)."/../include/common.inc.php");
 //$t1 = ExecTime();
$page = isset($_POST['p'])?$_POST['p']:1; //开始数
$per = 5;    //点击一次显示条数
$limit = (($page-1)*$per).",".$per;

$selquery = "SELECT * FROM #@__archives where flag like '%p%' order by id desc limit ".$limit; //调用全站带图的文章 从第五条开始

$dsql->SetQuery($selquery);
$dsql->Execute();
if ($row !== false)
{
while($row = $dsql->GetArray())
{
$arcurl = GetOneArchive($row['id']);
$arcurl = $arcurl['arcurl'];
$count = $row['id'];
$img = $row['litpic'];
$title = $row['title'];
$description = $row['description'];

  echo "<a href='$arcurl'>$title</a><br/>";
}

}else
{
echo "已经最后了
";
}

html内容部分

<----script type="text/javascript" src="http://cdnjscn.b0.upaiyun.com/libs/jquery/1.11.1/jquery.min.js">
 <----script type="text/javascript" src="/plus/base.js">
 
    ///////////// 首页用 {dede:arclist row='5' type='image.'} 频道列表页用 {dede:arclist row='5' type='image.' typeid='top' } 内容页或单页用 {dede:arclist type='image.' limit='0,5' typeid='top' }
     <li><br/><a href='[field:arcurl /]'>[field:fulltitle /]</a><br/>描述[field:fulltitle /]</li>
     {/dede:arclist}           
    </ul>
     <div class="readmore">
      <a href="javascript:void(0)" onclick="bioon.loadMore('#cms_list', '/plus/more.php', this)" >加载更多...</a>
     </div>
    

js部分 base.js

//显示更多js代码
var bioon = {};
bioon.loadMore = function(target, url, self) {
        $(self).data('text', $(self).text());
        $(self).text('Loading...');
        bioon.loadMoreConfig.target = $(target);
        bioon.loadMoreConfig.self = $(self);
        $.post(url, {p: bioon.loadMoreConfig.p}, function(data) {
                bioon.loadMoreConfig.p++;
                $(data).appendTo(bioon.loadMoreConfig.target);
                bioon.loadMoreConfig.self.text(bioon.loadMoreConfig.self.data('text'));
        });
};
bioon.loadMoreConfig = {p: 2};
bioon.showMore = function(self) {
        $(self).parent().parent().parent().find('.text3').css('max-height', 'inherit');
        $(self).prevAll().remove();
        $(self).remove();

}

源码下载

标签: none

添加新评论