ZENCART首页显示 Featured Categorie的方法

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

    需要在首页上显示类似兰亭的Featured Categories模块,


  2. <table width=100% border=0><tr>

  3. <?php

  4. $categories_query = "SELECT c.categories_id, cd.categories_name, c.categories_image, c.parent_id

  5. FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd

  6. WHERE c.parent_id = :parentID

  7. AND c.categories_id = cd.categories_id

  8. AND cd.language_id = :languagesID

  9. AND c.categories_status= '1'

  10. ORDER BY sort_order";

  11. $categories_query = $db->bindVars($categories_query, ':parentID', $current_category_id, 'integer');

  12. $categories_query = $db->bindVars($categories_query, ':languagesID', $_SESSION['languages_id'], 'integer');

  13. $categories_row = $db->Execute($categories_query);

  14. $number_of_categories = $categories_row->RecordCount();

  15. $new_products_category_id = $current_category_id;

  16. $rows = 0;

  17. while (!$categories_row->EOF) {

  18. $rows++;

  19. $cPath_new = zen_get_path($categories_row->fields['categories_id']);

  20. // strio out 0_ from top level

  21. $cPath_new = str_replace('=0_', '=', $cPath_new);

  22. $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';

  23. $newrow = false;

  24. if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != $number_of_categories))

  25. {

  26. $newrow = true;

  27. }

  28. if (!$categories_row->fields['categories_image']) !$categories_row->fields['categories_image'] = 'pixel_trans.gif';

  29. // start amazon style sub-cats in category lists

  30. // start config variables

  31. // display limit - adjust $limit to the number of subcats to display under parent category (4 or 5 seems right)

  32. $limit = '3';

  33. // subcat prefix - enter your preferred subcat prefix (bullets are default)

  34. $subs_indent = '&bull;&nbsp;';

  35. // 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

  36. $no_subs_indent = '&raquo;&nbsp;';

  37. $no_subs_prefix = 'View&nbsp;Products';

  38. //$no_subs_indent = '';

  39. //$no_subs_prefix = '';

  40. // sub-cats exceed display limit - indent and text prefix to display if sub-cats exceed display limit (eg - More {CATEGORY NAME})

  41. $limit_exceeded_indent = '&raquo;&raquo;&nbsp;';

  42. $limit_exceeded_prefix = 'More&nbsp;';

  43. // end config variables

  44. $parent_id = $categories_row->fields[categories_id];

  45. $sql = "select c.categories_id, cd.categories_name

  46. from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd

  47. where c.parent_id = '" . (int)$parent_id . "'

  48. and c.categories_id = cd.categories_id

  49. and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'

  50. and c.categories_status= '1'

  51. order by sort_order, cd.categories_name";

  52. $subcats = $db->Execute($sql);

  53. $subs_string = "";

  54. //if ($subcats->EOF) $subs_string .= '<br />' . $no_subs_indent . '<a href=' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '>' . $no_subs_prefix . '</a>';

  55. if ($subcats->EOF) $subs_string .= '';

  56. while (!$subcats->EOF) {

  57. if ($limit == $subcats->cursor) {

  58. //$subs_string .= '<br />' . $limit_exceeded_indent . '<a href=' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '>' . $limit_exceeded_prefix . $categories_row->fields[categories_name] . '</a>';

  59. $subs_string .= '';

  60. break;

  61. }

  62. $cPath_subs = $cPath_new . '_' . $subcats->fields[categories_id];

  63. $subs_string .= '<br />' . $subs_indent . '<a href=' . zen_href_link(FILENAME_DEFAULT, $cPath_subs) . '>' . $subcats->fields[categories_name] . '</a>';

  64. $subcats->MoveNext();

  65. }

  66. // end add sub-cat bullets to category rows

  67. ?>

  68. <td align="center" width="<?php echo $width; ?>" valign="top" style="border-bottom: 1px solid #e5e5e5;">

  69. <a href="<?php echo zen_href_link(FILENAME_DEFAULT, $cPath_new); ?>">

  70. <?php echo zen_image(DIR_WS_IMAGES . $categories_row->fields['categories_image'], $categories->fields['categories_name'], 80, 80); ?>

  71. </a>

  72. <br>

  73. <b style="font-size:120%;"><?php echo$categories_row->fields['categories_name']; ?></b><br>

  74. <span><?php echo$subs_string; ?></span>

  75. </td>

  76. <?php

  77. if ($newrow) {

  78. ?>

  79. </tr>

  80. <tr>

  81. <?php

  82. }

  83. ?>

  84. <?

  85. $categories_row->MoveNext();

  86. }

  87. ?>

  88. </table>


你可能感兴趣的:(zencart)