Home > Article > Backend Development > ECSHOP gets the top category id and name of the product on the product details page, ecshop top_PHP tutorial
is in the goods.php file,
Find $smarty->assign('goods', $goods);
Add the following code above it:
Method 1:
<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>
Method 2:
<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'];
Then, call the following in the product details template file goods.dwt:
Top category id: {$goods.topcat_id}
Top category name: {$goods.topcat_name}
$children = get_children($cat_id); Get all categories of the same level as the specified category and subcategories under this category
/**
* Get products under the category
*
* @access public
* @param string $children
* @return array
*/
function category_get_goods($children, $brand, $min, $max, $ext, $size , $page, $sort, $order)
See how category.php is used
The homepage calls the subcategory method under the specified category
The template homepage generally has classified products displayed by floors. In the upper right corner of each floor, there will be small categories arranged and displayed under the category:
In the past, some templates were here For static display, customers need to manually modify it one by one. Now the template center will tell you how to modify it to dynamic call. You only need to modify an ID.
1. Open the includes/lib_goods.php file in your file root directory and add a method in the last line:
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. Call in the template file, such as in the homepage index.dwt:
840081335196d70b11762414de037638
069bf637c282ed6c0b1f82624a7ea51a
147cabec52b7aac46d022a3b753e776c{$list.name}63505a6f727f70c8bd4066f3066dcb9d
1d317ef446a7156b681fc702c69f40cf
The "17" in brackets is the category id, modify it according to the product category of your website... The rest of the full text >>