zoukankan      html  css  js  c++  java
  • 简洁版Featured Category/Shop by Category模块

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

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

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

    <?php   

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

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

    WHERE      c.parent_id = :parentID

    AND        c.categories_id = cd.categories_id

    AND        cd.language_id = :languagesID

    AND        c.categories_status= '1'

    ORDER BY   sort_order";   

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

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

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

    $number_of_categories = $categories_row->RecordCount();   

    $new_products_category_id = $current_category_id;   

    $rows = 0;   

    while (!$categories_row->EOF) {   

    $rows++;   

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

    // strio out 0_ from top level

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

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

    $newrow = false;   

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

    {   

    $newrow = true;   

    }   

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

    // start amazon style sub-cats in category lists

    // start config variables

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

    $limit = '3';   

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

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

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

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

    $no_subs_prefix = 'View&nbsp;Products';   

    //$no_subs_indent = '';

    //$no_subs_prefix = '';

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

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

    $limit_exceeded_prefix = 'More&nbsp;';   

    // end config variables

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

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

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

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

    and        c.categories_id = cd.categories_id

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

    and        c.categories_status= '1'

    order by   sort_order, cd.categories_name";   

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

    $subs_string = "";   

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

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

    while (!$subcats->EOF) {   

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

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

    $subs_string .= '';   

    break;   

    }   

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

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

    $subcats->MoveNext();   

    }   

    // end add sub-cat bullets to category rows

    ?>   

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

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

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

    </a>   

    <br>   

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

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

    </td>   

    <?php   

    if ($newrow) {   

    ?>   

    </tr>   

    <tr>   

    <?php   

    }   

    ?>   

    <?   

    $categories_row->MoveNext();   

    }   

    ?>   

    </table> 

    后来整理了一下思路,简单了弄了个类似的,优缺点也各有存在。

    上面那个模块可以在大分类下显示小分类,代码贴上去就能用,不过冗余代码很多,比较难看懂

    本文中的这个代码很小,只能显示一个分类(子分类或父分类都可以),推荐分类的ID需要在代码中加入进去。

    代码:

    <div class="centerBoxWrapper" id="feacat">   

    <h2 class="centerBoxHeading">Featured Category</h2>   

    <?php   

        $feacatARR = array("3","4","5","6","","","","","");//这里填写推荐分类的id,需要填写多少就填多少,最好不要为空   

           

        foreach($feacatARR as $feaID){   

        $sql_feaimg = "select c.categories_image from " . TABLE_CATEGORIES . " c where c.categories_id = '" . $feaID . "'";   

        $categories_img = $db->Execute($sql_feaimg);   

        echo '<div class="feacatcontent centeredContent back" style=" 25%;">';   

        echo '<a href="'. zen_href_link(FILENAME_DEFAULT,'cPath='.$feaID) .'">' . zen_image(DIR_WS_IMAGES . $categories_img->fields['categories_image'], zen_get_categories_name($feaID), 150, 150) . '</a>';   

        echo '<h3 class="itemTitle"><a href="'. zen_href_link(FILENAME_DEFAULT,'cPath='.$feaID) .'">' . zen_get_categories_name($feaID) . '</a></h3>';   

        echo '</div>';   

        }   

    ?>   

    </div>  也可以新建一个php文件,把这段代码贴进去,然后在tpl_index_default.php中调用那个文件即可。

  • 相关阅读:
    第二月 day 2,内置函数
    第二月 day3 闭包,递归
    day4 装饰器
    第二月 day1生成器
    第一个月 总结
    day 16 迭代器
    day 15 编码
    Docker常用命令
    DRF源码刨析
    django中使用qiniu作为第三方存储
  • 原文地址:https://www.cnblogs.com/chenping/p/3759156.html
Copyright © 2011-2022 走看看