首页调单个产品分类的推荐产品,最新产品和热卖商品

在index.php文件里面有一段代码就是获得推荐产品,最新产品和热卖商品的,但是那是对所有分类而言的。其实要调单个分类呢,很简单,$act = !empty($_GET['act']) ? $_GET['act'] : '';在这句话下面的那段代码里面有个函数是获得产品分类ID的get_children($cat_id);调单个产品分类就把里面的变量换成你要调的相应的分类ID就行了。具体的实现如下代码:

 

$my_cat_rec_goods=array();//定义一个函数
$children=get_children(87);//获得分类ID
$my_cat_rec_goods[87]=get_category_recommend_goods('best', $children);//调取该分类下的推荐产品

 

呵呵,其实这个很简单的啦,这个是在同事那里学来的。。

 

然后呢说说首页调产品评论(必须显示产品的所有信息)

这个呢也是很简单的啦。。在message.php这个文件里面有个function get_msg_list($num, $start)函数,这个函数的作用是。。先把这个函数考到首页(index.php)文件下面。为了得到产品的所有信息就要对函数做一点小修改,先找到$msg[$rows['msg_time']]['id_value'] = $rows['id_value'];这句代码,在下面加一句代码$msg[$rows['msg_time']]['goods_info'] = $goods_res(这句代码的作用就是获得产品的详细信息);然后把下面的代码去掉(因为下面的代码是获得产品的名称和连接地址的)。其实我只需要调的是评论部分,所以这个函数里面有很多都可以删掉。修改后的代码如下:

 

 

View Code

function get_msg_list($num, $start)
{
/* 获取留言数据 */
$msg = array();

$sql = "(SELECT 'comment' AS tablename, comment_id AS ID, content AS msg_content, null AS msg_title, add_time AS msg_time, id_value AS id_value, comment_rank AS comment_rank, null AS message_img, user_name AS user_name, '6' AS msg_type ";
$sql .= " FROM " .$GLOBALS['ecs']->table('comment');
$sql .= "WHERE STATUS =1 AND comment_type =0) ";
$sql .= " UNION ";
$sql .= "(SELECT 'feedback' AS tablename, msg_id AS ID, msg_content AS msg_content, msg_title AS msg_title, msg_time AS msg_time, null AS id_value, null AS comment_rank, message_img AS message_img, user_name AS user_name, msg_type AS msg_type ";
$sql .= " FROM " .$GLOBALS['ecs']->table('feedback');
$sql .= " WHERE `msg_area`='1' AND `msg_status` = '1') ";
$sql .= " ORDER BY msg_time DESC ";

$res = $GLOBALS['db']->SelectLimit($sql, $num, $start);

while ($rows = $GLOBALS['db']->fetchRow($res))
{
for($i = 0; $i < count($rows); $i++)
{
$msg[$rows['msg_time']]['user_name'] = htmlspecialchars($rows['user_name']);
$msg[$rows['msg_time']]['msg_content'] = str_replace('\r\n', '<br />', htmlspecialchars($rows['msg_content']));
$msg[$rows['msg_time']]['msg_content'] = str_replace('\n', '<br />', $msg[$rows['msg_time']]['msg_content']);
$msg[$rows['msg_time']]['msg_time'] = local_date($GLOBALS['_CFG']['time_format'], $rows['msg_time']);
$msg[$rows['msg_time']]['msg_type'] = $GLOBALS['_LANG']['message_type'][$rows['msg_type']];
$msg[$rows['msg_time']]['msg_title'] = nl2br(htmlspecialchars($rows['msg_title']));
$msg[$rows['msg_time']]['message_img'] = $rows['message_img'];
$msg[$rows['msg_time']]['tablename'] = $rows['tablename'];

if(isset($rows['order_id']))
{
$msg[$rows['msg_time']]['order_id'] = $rows['order_id'];
}
$msg[$rows['msg_time']]['comment_rank'] = $rows['comment_rank'];
$msg[$rows['msg_time']]['id_value'] = $rows['id_value'];

/*如果id_value为true为商品评论,根据商品id取出商品名称*/
if($rows['id_value'])
{
$sql_goods = "SELECT * FROM ".$GLOBALS['ecs']->table('goods');
$sql_goods .= "WHERE goods_id= ".$rows['id_value'];
$goods_res = $GLOBALS['db']->getRow($sql_goods);
$msg[$rows['msg_time']]['goods_info'] = $goods_res;//获得商品的详细信息
}
}

$msg[$rows['msg_time']]['tablename'] = $rows['tablename'];
$id = $rows['ID'];
$reply = array();
if(isset($msg[$rows['msg_time']]['tablename']))
{
$table_name = $msg[$rows['msg_time']]['tablename'];

if ($table_name == 'feedback')
{
$sql = "SELECT user_name AS re_name, user_email AS re_email, msg_time AS re_time, msg_content AS re_content ,parent_id".
" FROM " .$GLOBALS['ecs']->table('feedback') .
" WHERE parent_id = '" . $id. "'";
}
else
{
$sql = 'SELECT user_name AS re_name, email AS re_email, add_time AS re_time, content AS re_content ,parent_id
FROM ' . $GLOBALS['ecs']->table('comment') .
" WHERE parent_id = $id ";

}
$reply = $GLOBALS['db']->getRow($sql);
if ($reply)
{
$msg[$rows['msg_time']]['re_name'] = $reply['re_name'];
$msg[$rows['msg_time']]['re_email'] = $reply['re_email'];
$msg[$rows['msg_time']]['re_time'] = local_date($GLOBALS['_CFG']['time_format'], $reply['re_time']);
$msg[$rows['msg_time']]['re_content'] = nl2br(htmlspecialchars($reply['re_content']));
}
}

}
return $msg;
}

 

调评论的部分呢就结束了,其实我也不知道我的这个对不对,不过我能调出来哦。希望能帮到你们吧!

下面呢我来说说调单个文章分类的最新文章这个是我在网上找到的,然后就把它一起放在这里了

 

View Code

/**
* 获得指定栏目最新的文章列表。
*
* @access private
* @return array
*/
function index_get_class_articles($cat_aid, $cat_num)
{
$sql = "SELECT article_id, title,open_type,cat_id,file_url FROM " .$GLOBALS['ecs']->table('article'). " WHERE cat_id = ".$cat_aid." and is_open = 1 LIMIT " . $cat_num;
$res = $GLOBALS['db']->getAll($sql);
$arr = array();
foreach ($res AS $idx => $row)
{
$arr[$idx]['id'] = $row['article_id'];
$arr[$idx]['title'] = $row['title'];
$arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?
sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];
$arr[$idx]['cat_name'] = $row['cat_name'];
$arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
$arr[$idx]['url'] = $row['open_type'] != 1 ?build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);
$arr[$idx]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id']));
}
return $arr;
}

 

然后再在这句代码下面加上这句话

$smarty->assign('new_articles',    index_get_new_articles());   // 最新文章

模版里面怎么用大家应该知道吧,这里就不多说了!

评论框那里有个等级的选择,如果为了样式的好看要去掉,最简单的方法就是把它隐藏。

 

 

 

作者:沐雪
文章均系作者原创或翻译,如有错误不妥之处,欢迎各位批评指正。本文版权归作者所有,如需转载恳请注明。
​​​ 为之网-热爱软件编程 http://www.weizhi.cc/​