怎么调用woocommerce分类目录,指定分类下的指定商品

 我来答
城南明月羿当年
2015-04-13 · 知道合伙人生活技巧行家
城南明月羿当年
知道合伙人生活技巧行家
采纳数:24666 获赞数:123229
计算机爱好者

向TA提问 私信TA
展开全部
方法/步骤
在系统目录文件找到includes/lib_goods.php 这个文件打开在此页最底部加入以下函数代码:
/**
* 首页获取指定分类产品
*
* @access public
* @param string $cat_id53_best_goods
* @param array $cat_id53_best_goods
* @return array
*/
function get_cat_id_goods_list($cat_id = '', $num = '') {
$sql = 'Select g.goods_id, g.cat_id,c.parent_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, " .
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, " .
"g.is_best, g.is_new, g.is_hot, g.is_promote " .
'FROM ' . $GLOBALS ['ecs']->table ( 'goods' ) . ' AS g ' .
'LEFT JOIN ' . $GLOBALS ['ecs']->table ( 'category' ) . ' AS c ON c.cat_id = g.cat_id ' .
"LEFT JOIN " . $GLOBALS ['ecs']->table ( 'member_price' ) . " AS mp " .
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
"Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " .
$sql .= " AND (c.parent_id =" . $cat_id . " OR g.cat_id = " . $cat_id . " OR g.cat_id " . db_create_in ( array_unique ( array_merge ( array (
$cat_id
), array_keys ( cat_list ( $cat_id, 0, false ) ) ) ) ) . ")";
$sql .= " LIMIT $num";
$res = $GLOBALS ['db']->getAll ( $sql );
$goods = array ();
foreach ( $res as $idx => $row ) {
$goods [$idx] ['id'] = $row ['article_id'];
$goods [$idx] ['id'] = $row ['goods_id'];
$goods [$idx] ['name'] = $row ['goods_name'];
$goods [$idx] ['brief'] = $row ['goods_brief'];
$goods [$idx] ['brand_name'] = $row ['brand_name'];
$goods [$idx] ['goods_style_name'] = add_style ( $row ['goods_name'], $row ['goods_name_style'] );
$goods [$idx] ['short_name'] = $GLOBALS ['_CFG'] ['goods_name_length'] > 0 ? sub_str ( $row ['goods_name'], $GLOBALS ['_CFG'] ['goods_name_length'] ) : $row ['goods_name'];
$goods [$idx] ['short_style_name'] = add_style ( $goods [$idx] ['short_name'], $row ['goods_name_style'] );
$goods [$idx] ['market_price'] = price_format ( $row ['market_price'] );
$goods [$idx] ['shop_price'] = price_format ( $row ['shop_price'] );
$goods [$idx] ['thumb'] = empty ( $row ['goods_thumb'] ) ? $GLOBALS ['_CFG'] ['no_picture'] : $row ['goods_thumb'];
$goods [$idx] ['goods_img'] = empty ( $row ['goods_img'] ) ? $GLOBALS ['_CFG'] ['no_picture'] : $row ['goods_img'];
$goods [$idx] ['url'] = build_uri ( 'goods', array (
'gid' => $row ['goods_id']
), $row ['goods_name'] );
}
return $goods;
}
打开系统根目录下index.php文件加入如下代码,如果要在别的页面调用加到别的页面:
$smarty->assign('cat_id_goods_list_86', get_cat_id_goods_list(86,9));
// 指定商品调用
//其中86指的调用的栏目ID,9指的是调用商品的数量。
在首页模版中调用即可,如下:
<!--{foreach from=$cat_id_goods_list_86 item=goods}-->
<li>   <a href="{$goods.url}" target="_blank"> <img src="{$goods.thumb}" alt="{$goods.name|escape:html}" /></a> <span class="a_title"> <a href="{$goods.url}" title="{$goods.name|escape:html}" target="_blank"> {$goods.short_style_name}</a> </span> <div style="text-indent: 5px;">市场价 <span class="del">{$goods.market_price}</span></div> <div style="text-indent: 5px;"><span class="red">售 价 {$goods.shop_price}</span></div></li>
<!--{/foreach}-->
亚远景信息科技
2024-12-11 广告
上海亚远景信息科技有限公司是国内汽车行业咨询及评估领军机构之一,深耕于ASPICE、敏捷SPICE、ISO26262功能安全、ISO21434车辆网络安全领域,拥有20年以上的行业经验,专精于培训、咨询及评估服务,广受全球车厂及供应商赞誉,... 点击进入详情页
本回答由亚远景信息科技提供
水岛犯虹
2015-04-13
知道答主
回答量:13
采纳率:0%
帮助的人:5.6万
展开全部
rtvprtjb krvd nbvy mnbvdbndvc
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式