专注于高品质PHP技术等信息服务于一体 [STIEMAP] [RSS]

百度提供的广告:
PHP
当前位置:首页 > 技术文档 > PHP >  > 
分享个 CMS 生成一二级分类文章列表源码

require_once '../admin/conn.php';
require_once '../admin/function.php';
$dbconn=new dbconn();
$dbconn->geconn();
$typeid = intval($_GET['id']);
$n = intval($_GET['n']);
$page_size = 6;
$all_page = 0;
//文章分类
$sql = "select * from arc_type where id = $typeid";
$rs = mysql_query($sql);
$arc_type = mysql_fetch_array($rs);
if(0 == $arc_type['pid'])
{
    $arc_top_type = $arc_type;
}
else
{
    //文章顶级分类
    $sql = "select * from arc_type where id = {$arc_type['pid']}";
    $rs = mysql_query($sql);
    $arc_top_type = mysql_fetch_array($rs);
}
//主分类下子类ID
$sql = "select * from arc_type where pid = {$arc_top_type['id']}";
$rs = mysql_query($sql);
$typeids = $arc_top_type['id'];
while($row = mysql_fetch_array($rs))
{
    $typeids .= ",{$row['id']}";
    $arc_types[] = $row;
}
//手动分页
if($arc_top_type == $arc_type)//顶级列表
{
    $sql = "select id,file_name,description,content,send_time,title from article where typeid in ($typeids) ";
    //分页总记录数
    $count_sql = "select count(id) count ".stristr($sql,'from');
    $rs = mysql_query($count_sql);
    $row = mysql_fetch_array($rs);
    $count = $row['count'];
    $all_page = floor(($count-1)/$page_size) + 1 ;
    //分页sql
    $sql .= " limit ".($n*$page_size).",$page_size ";
    $rs = mysql_query($sql);
    while($row = mysql_fetch_array($rs))
    {
        $list[] = $row;
    }
   
}
else //二级列表
{
    $sql = "select id,file_name,description,content,send_time,title from article where typeid = $typeid ";
    //分页总记录数
    $count_sql = "select count(id) count ".stristr($sql,'from');
    $rs = mysql_query($count_sql);
    $row = mysql_fetch_array($rs);
    $count = $row['count'];
    $all_page = floor(($count-1)/$page_size) + 1 ;
    //分页sql
    $sql .= " limit ".($n*$page_size).",$page_size ";
    $rs = mysql_query($sql);
    while($row = mysql_fetch_array($rs))
    {
        $list[] = $row;
    }
}

可以根据,文章分类生成 文章 HTML 代码,只限2级分类。