帝国cms 加载更多的实现(父栏目以及子栏目都可以实现)

1、找到加载更多的按钮,设置好id(最好用id,比较容易遍历)。

<div class="pagelist"> <span id="loadmore" class="btn" style="display: block;">加载更多</span> </div>

2、找到列表内容模板的标签,也设置好id。

<ul id="showajaxnews" style="opacity: 1; top: 0px;">
 
        [!--empirenews.listtemp--]<!--list.var1-->[!--empirenews.listtemp--]
 
</ul>

3、ajax放到加载更多的下边,记得一定要引入Jquery.

<script>
  $(function () {
    var i = 1;
    $('#loadmore').click(function () {
      $.ajax({
        url: '域名/e/action/getmore.php',
        type: 'POST',
        data: {
          "next": i,
          'table': 'news',
          'classid': '[!--self.classid--]', /*这个标签获取的当前id*/
          'action': 'getmorenews',
          'limit': 4,
          'small_length': 120
        },
        dataType: 'html',
        beforeSend: function () {
          $("#loadmore").show().html(
            '<img src="/images/loaduai.gif" alt="正在努力加载中...');
          $('#loadmore').attr('disabled', 'disabled');
        },
        success: function (data) {
          if (data) {
            $("#showajaxnews").append(data);
            $("#loadmore").removeAttr('disabled');
            $("#loadmore").html('点击加载更多');
            i++;
          } else {
            $("#loadmore").show().html("已全部加载完毕!");
            $('#loadmore').attr('disabled', 'disabled');
            return false;
          }
        }
      });
    });
  });
</script>

4、下边标红的,我这里做了一个$classid的判断,意思就是当栏目是父栏目7的时候,调用栏目id 8 和 9 的所有数据。按照自己的情景设置即可。

<?php
require('../class/connect.php');
require('../class/db_sql.php');
require('../data/dbcache/class.php');
if ($_POST[action] == 'getmorenews') {
    $table = htmlspecialchars($_POST[table]);
    if (empty($_POST[orderby])) {
        $orderby = 'newstime';
    } else {
        $orderby = htmlspecialchars($_POST[orderby]);
    }
    if (empty($_POST[myorder])) {
        $myorder = 'desc';
    } else {
        $myorder = 'asc';
    }
    if (empty($_POST[limit])) {
        $limit = 6;
    } else {
        $limit = (int) $_POST[limit];
    }
    if (empty($_POST[classid])) {
        $where = null;
    } else if ($_POST[classid] == 7) {
        $where = 'where classid in("8,9")';
    } else {
        $where = 'where classid in(' . $_POST[classid] . ')';
    }
    if (empty($_POST[length])) {
        $length = 50;
    } else {
        $length = (int) $_POST[length];
    }
    if (empty($_POST[small_length])) {
        $small_length = 500;
    } else {
        $small_length = (int) $_POST[small_length];
    }
 
    // next:第几页
    // table:调用数据表
    // limit:每次调用数量
    // small_length:简介截取字符数
    // length:标题截取字符数
    // classid:调用栏目,允许多个,如1,2,3,4  特别注意,必须是调用同一数据表的栏目
    // orderby:排序,默认是newstime,传什么就按什么来排序,如 id
    // myorder:正反序,默认是asc,传值怎为desc
 
    $link = db_connect();
    $empire = new mysqlquery();
    $num = (int) $_POST['next'] * $limit;
 
    if ($table) {
        $sql = $empire->query("SELECT * FROM `" . $dbtbpre . "ecms_" . $table . "` $where order by $orderby $myorder limit $num,$limit");
 
        while ($r = $empire->fetch($sql)) {
 
            if ($r[mtitlepic] == '') {
                $r[mtitlepic] = $public_r[news . url] . "e/data/images/notimg.gif";
            }
            $oldtitle = stripSlashes($r[title]);
            $title = sub($oldtitle, '', $length);
            $smalltext = stripSlashes($r[smalltext]);
            $smalltext = sub($smalltext, '', $small_length);
            $classname = $class_r[$r[classid]][classname];
            $newsurl = $public_r[newsurl];
            $classurl = $newsurl . $class_r[$r[classid]][classpath];
            $urls = sys_ReturnBqTitleLink($r);
 
            ?>
            <!-- 以下代码是显示列表的标签模板 ,按照情景修改即可。-->
            <li>
                <a href="<?= $urls ?>">
                    <div class="img">
                        <img src="<?= $r[titlepic] ?>" class="lazy"></div>
                    <div class="con">
                        <h2>
                            <?= $r[title] ?>
                        </h2>
                        <p>
                            <?= $r[smalltext] ?>
                        </p>
                        <span>
                            <?= date("Y-m-d", $r[newstime]) ?>
                        </span>
                    </div>
                    <div class="more">
                        <span></span>
                    </div>
                </a>
            </li>
<?php
        }
    }
}
db_close();
$empire = null;
?>

5、建立一个getmore.php文件,把上边代码上传到/e/action/文件中。

 

完成。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值