首 页  >>  E商学院  >>  zencart百科  >>  网站增加类似兰亭Featured Categories模块

网站增加类似兰亭Featured Categories模块

网站首页的默认文件是tpl_index_default.php

需要在首页上显示类似兰亭的Featured Categories模块,需要添加以下代码:

 

  1. <table width=100% border=0><tr>   
  2. <?php   
  3. $categories_query = "SELECT c.categories_id, cd.categories_name, c.categories_image, c.parent_id
  4. FROM   " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd  
  5. WHERE      c.parent_id = :parentID  
  6. AND        c.categories_id = cd.categories_id  
  7. AND        cd.language_id = :languagesID  
  8. AND        c.categories_status= '1'  
  9. ORDER BY   sort_order";   
  10. $categories_query = $db->bindVars($categories_query, ':parentID', $current_category_id, 'integer');   
  11. $categories_query = $db->bindVars($categories_query, ':languagesID', $_SESSION['languages_id'], 'integer');   
  12. $categories_row = $db->Execute($categories_query);   
  13. $number_of_categories = $categories_row->RecordCount();   
  14. $new_products_category_id = $current_category_id;   
  15. $rows = 0;   
  16. while (!$categories_row->EOF) {   
  17. $rows++;   
  18. $cPath_new = zen_get_path($categories_row->fields['categories_id']);   
  19. // strio out 0_ from top level   
  20. $cPath_new = str_replace('=0_', '=', $cPath_new);   
  21. $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';   
  22. $newrow = false;   
  23. if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != $number_of_categories))   
  24. {   
  25. $newrow = true;   
  26. }   
  27. if (!$categories_row->fields['categories_image']) !$categories_row->fields['categories_image'] = 'pixel_trans.gif';   
  28. // start amazon style sub-cats in category lists   
  29. // start config variables   
  30. // display limit - adjust $limit to the number of subcats to display under parent category (4 or 5 seems right)   
  31. $limit = '3';   
  32. // subcat prefix - enter your preferred subcat prefix (bullets are default)   
  33. $subs_indent = '&bull;&nbsp;';   
  34. // no sub-cats - display this if there are no sub-cats within a category. Leave both values blank (see below) if you want to display only the category name   
  35. $no_subs_indent = '&raquo;&nbsp;';   
  36. $no_subs_prefix = 'View&nbsp;Products';   
  37. //$no_subs_indent = '';   
  38. //$no_subs_prefix = '';   
  39. // sub-cats exceed display limit - indent and text prefix to display if sub-cats exceed display limit (eg - More {CATEGORY NAME})   
  40. $limit_exceeded_indent = '&raquo;&raquo;&nbsp;';   
  41. $limit_exceeded_prefix = 'More&nbsp;';   
  42. // end config variables   
  43. $parent_id = $categories_row->fields[categories_id];   
  44. $sql = "select c.categories_id, cd.categories_name
  45. from   " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd  
  46. where      c.parent_id = '" . (int)$parent_id . "'  
  47. and        c.categories_id = cd.categories_id  
  48. and        cd.language_id = '" . (int)$_SESSION['languages_id'] . "'  
  49. and        c.categories_status= '1'  
  50. order by   sort_order, cd.categories_name";   
  51. $subcats = $db->Execute($sql);   
  52. $subs_string = "";   
  53. //if ($subcats->EOF) $subs_string .= '<br />' . $no_subs_indent . '<a href=' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '>' . $no_subs_prefix . '</a>';   
  54. if ($subcats->EOF) $subs_string .= '';   
  55. while (!$subcats->EOF) {   
  56. if ($limit == $subcats->cursor) {   
  57. //$subs_string .= '<br />' . $limit_exceeded_indent . '<a href=' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '>' . $limit_exceeded_prefix . $categories_row->fields[categories_name] . '</a>';   
  58. $subs_string .= '';   
  59. break;   
  60. }   
  61. $cPath_subs = $cPath_new . '_' . $subcats->fields[categories_id];   
  62. $subs_string .= '<br />' . $subs_indent . '<a href=' . zen_href_link(FILENAME_DEFAULT, $cPath_subs) . '>' . $subcats->fields[categories_name] . '</a>';   
  63. $subcats->MoveNext();   
  64. }   
  65. // end add sub-cat bullets to category rows   
  66. ?>   
  67. <td align="center" width="<?php echo $width; ?>" valign="top" style="border-bottom: 1px solid #e5e5e5;">   
  68. <a href="<?php echo zen_href_link(FILENAME_DEFAULT, $cPath_new); ?>">   
  69. <?php echo zen_image(DIR_WS_IMAGES . $categories_row->fields['categories_image'], $categories->fields['categories_name'], 80, 80); ?>   
  70. </a>   
  71. <br>   
  72. <b style="font-size:120%;"><?php echo $categories_row->fields['categories_name']; ?></b><br>   
  73. <span><?php echo $subs_string; ?></span>   
  74. </td>   
  75. <?php   
  76. if ($newrow) {   
  77. ?>   
  78. </tr>   
  79. <tr>   
  80. <?php   
  81. }   
  82. ?>   
  83. <?   
  84. $categories_row->MoveNext();   
  85. }   
  86. ?>   
  87. </table>  

 

这段代码就组成了一个模块,需要的时候,调用在你需要显示的地方即可!


点击次数:1938  发布日期:2014-05-22  【打印此页】  【关闭