ECSHOP在商品详细页面上获取该商品的顶级分类id和名称,ecshop顶级_PHP教程

WBOY
Freigeben: 2016-07-13 10:23:45
Original
1036 Leute haben es durchsucht

ECSHOP在商品详细页面上获取该商品的顶级分类id和名称,ecshop顶级

在 goods.php 文件,

找到 $smarty->assign('goods', $goods); 
在它上面增加下面代码:

方法一:

<span>$cat_arr</span> = get_parent_cats(<span>$goods</span>['cat_id'<span>]);
</span><span>foreach</span> (<span>$cat_arr</span> <span>AS</span> <span>$val</span><span>) <br />{
  </span><span>$goods</span>['topcat_id']=<span>$val</span>['cat_id'<span>];
</span><span>  $goods</span>['topcat_name']=<span>$val</span>['cat_name'<span>];
}</span>
Nach dem Login kopieren

方法二:

<span>$cat_arr</span> = get_parent_cats(<span>$goods</span>['cat_id'<span>]);
</span><span>$topcat_arr</span> = <span>end</span>(<span>$cat_arr</span><span>);
</span><span>$goods</span>['topcat_id']=<span>$topcat_arr</span>['cat_id'<span>];
</span><span>$goods</span>['topcat_name']=<span>$topcat_arr</span>['cat_name'];
Nach dem Login kopieren

然后,在商品详情模板文件 goods.dwt 中调用如下:

顶级分类id:{$goods.topcat_id}
顶级分类名称name:{$goods.topcat_name}

ecshop中首页获取了一个分类的cat_id,怎调用它的以及它子类的商品?

$children = get_children($cat_id); 获得指定分类同级的所有分类以及该分类下的子分类

/**
* 获得分类下的商品
*
* @access public
* @param string $children
* @return array
*/
function category_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order)

看看category.php 是怎么用的
 

ecshop怎调用指定id的顶级分类以及子分类名称

首页调用指定分类下子分类方法
模板首页一般都有分楼层显示的分类商品,每个楼层右上角会有该分类下小分类排列显示的:
以往有些模板这里都是静态显示的,需要客户手动依次修改,现在模板中心告诉您怎样修改成动态调用,只需修改一个id即可。
1.打开您的文件根目录下 includes/lib_goods.php 文件,在最后一行加入一个方法:
function get_parent_id_tree($parent_id)
{
$three_c_arr = array();
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 ";
if ($GLOBALS['db']->getOne($sql))
{
$child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
'FROM ' . $GLOBALS['ecs']->table('category') .
"WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC ";
$res = $GLOBALS['db']->getAll($child_sql);
foreach ($res AS $row)
{
if ($row['is_show'])
$three_c_arr[$row['cat_id']]['id'] = $row['cat_id'];
$three_c_arr[$row['cat_id']]['name'] = $row['cat_name'];
$three_c_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
}
}
return $three_c_arr;
}

2. 在模板文件里调用,如首页index.dwt中 :

$this->assign('thiscid1', get_parent_id_tree(17));//调用父级分类的下级分类
?>


{$list.name}


括号里的“17”为分类id,按照您的网站商品分类修改......余下全文>>
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/834762.htmlTechArticleECSHOP在商品详细页面上获取该商品的顶级分类id和名称,ecshop顶级 在 goods.php 文件, 找到 $smarty-assign('goods', $goods); 在它上面增加下面代码:...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!