请问一下.能不能在某个页面调用所有文章分类下的前10条文章?

2016-07-07 16:14 来源:www.chinab4c.com 作者:ecshop专家

请问一下.能不能在某个页面调用所有文章分类下的前10条文章?

搜索了很长时间.有看到是指定分类下的前10条文章.

不知道调用所有分类下的前10条.程序应该怎么写呢?

回答:
lz可以参考不同分类下,不同的广告方法。来套用更改下引用,不知道行不行

$parent_id = 0;
$sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('article_cat') . " WHERE cat_id = '$cat_id'";
$parentid=$GLOBALS['db']->getOne($sql);
if($parentid==0)
{
$parent_id = $cat_id;
}
else
{
$parent_id = $parentid;
}
/*
判断当前分类中全是是否是底级分类,
如果是取出底级分类上级分类,
如果不是取当前分类及其下的子分类
*/
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('article_cat') . " WHERE parent_id = '$parent_id'";
if ($GLOBALS['db']->getOne($sql))
{
/* 获取当前分类及其子分类 */
$sql = 'SELECT a.cat_id, a.cat_name, a.sort_order AS parent_order, a.cat_id, ' .
'b.article_id AS child_id, b.title AS child_name ' .
'FROM ' . $GLOBALS['ecs']->table('article_cat') . ' AS a ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('article') . ' AS b ON b.cat_id = a.cat_id ' .
"WHERE a.cat_type=1 ORDER BY parent_order ASC, a.cat_id ASC";
}
else
{
/* 获取当前分类及其父分类 */
$sql = 'SELECT a.cat_id, a.cat_name, b.article_id AS child_id, b.title AS child_name, a.sort_order ' .
'FROM ' . $GLOBALS['ecs']->table('article_cat') . ' AS a ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('article') . ' AS b ON b.cat_id = a.cat_id ' .
"WHERE a.cat_type = 1 ORDER BY sort_order ASC limit 0,10";
}
$res = $GLOBALS['db']->getAll($sql);

$cat_arr = array();
foreach ($res AS $row)
{
$cat_arr[$row['cat_id']]['id']= $row['cat_id'];
$cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
$cat_arr[$row['cat_id']]['url']= build_uri('article_cat', array('acid' => $row['cat_id']), $row['cat_name']);

if ($row['child_id'] != NULL)
{
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['id']= $row['child_id'];
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['name'] = $row['child_name'];
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['url']= build_uri('article', array('aid' => $row['child_id']), $row['child_name']);
}
}

return $cat_arr;


楼主看看这个行不行
这个是根据系统的代码修改过的

好的..感谢楼上提示...我试试

恩有问题再发出来或联系我哈

再帮忙看看我的另一个新贴..有点问题