首页 » ZenCart » ZenCart分析 » 阅读文章
ZenCart分类相关函数分析
zen_get_category_name()
zen_get_category_name()函数位于 /includes/functions/functions_lookups.php 文件中(大约274行),主要用于分类名称输出
参数 | 作用 |
---|---|
$category_id | 分类id |
$fn_language_id | 语言ID,一般为$_SESSION['languages_id'],即当前语言下的分类名称 |
代码分析
function zen_get_category_name($category_id, $fn_language_id) { global $db; $category_query = "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $category_id . "' and language_id = '" . $fn_language_id . "'"; $category = $db->Execute($category_query); return $category->fields['categories_name']; }
示例
<?php //输出当前语言下,分类ID为3的分类的名称 echo zen_get_category_name(3, $_SESSION['languages_id']) ; ?>
zen_get_category_description()
zen_get_category_description()函数位于 /includes/functions/functions_lookups.php 文件中(大约290行),主要用于分类描述输出
参数 | 作用 |
---|---|
$category_id | 分类id |
$fn_language_id | 语言ID,一般为$_SESSION['languages_id'],即当前语言下的分类描述 |
代码分析
function zen_get_category_description($category_id, $fn_language_id) { global $db; $category_query = "select categories_description from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $category_id . "' and language_id = '" . $fn_language_id . "'"; $category = $db->Execute($category_query); return $category->fields['categories_description']; }
示例
<?php //输出当前语言下,分类ID为3的分类的描述 echo zen_get_category_description(3, $_SESSION['languages_id']) ; ?>
GetFullcPath()
这个函数是我在研究别的插件时发现,用于输出分类连接时的cpath部分的内容,配合zen_href_link()输出分类链接
参数 | 作用 |
---|---|
$cID | 分类ID |
代码分析
function GetFullcPath($cID){ global $db; static $parent_cache = array(); $cats = array(); $cats[] = $cID; $parent = $db->Execute("SELECT parent_id, categories_id FROM " . TABLE_CATEGORIES . " WHERE categories_id=" . (int)$cID); while(!$parent->EOF && $parent->fields['parent_id'] != 0) { $parent_cache[(int)$parent->fields['categories_id']] = (int)$parent->fields['parent_id']; $cats[] = $parent->fields['parent_id']; if(isset($parent_cache[(int)$parent->fields['parent_id']])) { $parent->fields['parent_id'] = $parent_cache[(int)$parent->fields['parent_id']]; } else { $parent = $db->Execute("SELECT parent_id, categories_id FROM " . TABLE_CATEGORIES . " WHERE categories_id=" . (int)$parent->fields['parent_id']); } } $cats = array_reverse($cats); $cPath = implode('_', $cats); return $cPath; }
示例
<?php //输出分类ID为3的分类的连接 echo zen_href_link(FILENAME_DEFAULT,'cPath='.GetFullcPath(3)); ?>
声明: 本文由Ezencart原创,转载请保留链接:ZenCart分类相关函数分析
评论 共0条 (RSS 2.0) 发表评论