<?php
define('CURSCRIPT', 'article');
require_once './engine/common.inc.php';
if(!array_key_exists($categoryid,$articlecategory)){
	showmsg("文章分类不存在");
}else{
	if($articlecategory[$categoryid]['pid']!=$pid){
	showmsg("文章上级分类不存在");
	}
}
if(!$pid){
	foreach($articlecategory as $key => $val){
		if($val['pid']==$categoryid){
			$in_id[]=$key;
		}
	}
}
$in_id[]=$categoryid;
$in_id_str=implode(",",$in_id);
@extract($articlecategory[$categoryid]);
if(!$displayway){
	$aid=$db->result($db->query("SELECT aid FROM g_articles where categoryid=$categoryid order by ord desc"),0);
	$url="location:viewarticle.php?aid=".$aid;
	gheader($url);
}

$siteheadtitle=implode(' ',array($categorytitle,$sitename,$sitekeywords));

$curpage=isset($page)?$page:1;
$startrecord=($curpage-1)*$pagerecords;
$toparticles=array();
$totalrecord=$db->result($db->query("SELECT count(*) FROM g_articles WHERE categoryid in ($in_id_str) and top = 0"),0);

	$topq = $db->query("SELECT * FROM g_articles WHERE categoryid in ($in_id_str) and top = 1 ORDER BY ord DESC limit 0,5");
	$key = 0;
	while($toparticle=$db->fetch_array($topq))
		{
			$toparticles[$key]=$toparticle;
			$key++;
		}
	$q = $db->query("SELECT * FROM g_articles WHERE categoryid in ($in_id_str) and top = 0 ORDER BY ord DESC LIMIT $startrecord , $pagerecords");
	$key = 0;

	while($article=$db->fetch_array($q)){
		$articles[$key]=$article;
		$key++;
	}
$multipage=multi($totalrecord, $pagerecords, $curpage, "articledisplay.php?pid=".$pid."&categoryid=".$categoryid);
include($templatedir."articledisplay.tpl.php");
?>