zencart分类列表模块分析
模块说明
根据$cPath参数查询数据表,返回分类列表.$cPath不存在时返回顶级分类列表,当$cPath存在时分析$cPath_array数组,根据数组元素查找相应下级分类,
引用类文件category_tree.php
第一遍查询,得到以ID为键的二维数组tree,this->tree[categories_id] = array(
'name' => categories_name,
'parent' => parent_id,
'level' => 0/1/2,
'path' => c0/c0_c1,
'image' => categories_image,
'next_id' => nextid/false
)
利用tree进行二次查询,生成自然数字为键的二维数组box_categories_array,返回该数组.
$this->box_categories_array[0-9]= array(
'top' => 'true'/'false',
'path' => cPath=cid,
'current' => true/false,
'image' => image,
'name' => name,
'has_sub_cat' => true/false,
'count' => count/0,
)
模块程序文件
<?php $main_category_tree = new category_tree; $row = 0; $box_categories_array = array (); $check_categories = $db ->Execute( "select categories_id from " . TABLE_CATEGORIES . " where categories_status=1 limit 1" ); if ( $check_categories ->RecordCount() > 0) { $box_categories_array = $main_category_tree ->zen_category_tree(); } require ( $template ->get_template_dir( 'tpl_categories.php' ,DIR_WS_TEMPLATE, $current_page_base , 'sideboxes' ). '/tpl_categories.php' ); $title = BOX_HEADING_CATEGORIES; $title_link = false; require ( $template ->get_template_dir( $column_box_default , DIR_WS_TEMPLATE, $current_page_base , 'common' ) . '/' . $column_box_default ); ?> |
模板内容文件
<?php $content = "" ; $content .= '<div id="' . str_replace ( '_' , '-' , $box_id . 'Content' ) . '" class="sideBoxContent">' . "\n" ; for ( $i =0; $i <sizeof( $box_categories_array ); $i ++) { switch (true) { case ( $box_categories_array [ $i ][ 'top' ] == 'true' ): $new_style = 'category-top' ; break ; case ( $box_categories_array [ $i ][ 'has_sub_cat' ]): $new_style = 'category-subs' ; break ; default : $new_style = 'category-products' ; } if (zen_get_product_types_to_category( $box_categories_array [ $i ][ 'path' ]) == 3 or ( $box_categories_array [ $i ][ 'top' ] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) { // skip if this is for the document box (==3) } else { $content .= '<a class=" . $new_style . " href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array [ $i ][ 'path' ]) . '">' ; if ( $box_categories_array [ $i ][ 'current' ]) { if ( $box_categories_array [ $i ][ 'has_sub_cat' ]) { $content .= '<span class="category-subs-parent">' . $box_categories_array [ $i ][ 'name' ] . '</span>' ; } else { $content .= '<span class="category-subs-selected">' . $box_categories_array [ $i ][ 'name' ] . '</span>' ; } } else { $content .= $box_categories_array [ $i ][ 'name' ]; } if ( $box_categories_array [ $i ][ 'has_sub_cat' ]) { $content .= CATEGORIES_SEPARATOR; } $content .= '</a>' ; if (SHOW_COUNTS == 'true' ) { if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array [ $i ][ 'count' ] == 0) or $box_categories_array [ $i ][ 'count' ] >= 1) { $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array [ $i ][ 'count' ] . CATEGORIES_COUNT_SUFFIX; } } $content .= '<br />' . "\n" ; } } $content .= '</div>' ; ?> |
相应数据表
categoriescategories_id
categories_image
parent_id
sort_order
date_added
last_modified
categories_status
categories_description
categories_id
language_id
categories_name
categories_description
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步