听说code能改变world,所以就学了

易企cms获取分类下的指定个数产品方法

易企cms默认版本能获取指定分类的所有产品,但是不能获取指定的个数,为了能够获取指定的个数,我找到了GetProductList方法进行了改进:

1.找到根目录下的include/product.class.php文件搜索关键字"GetProductList"将GetProductList方法替换为如下代码,

    function GetProductList($cid,$skip=0,$take=10,$orderby="adddate desc",$all=false)
    {
        global $yiqi_db;
        $categorydata = new Category();        
        $exist = $categorydata->ExistCategory($cid);
        if($exist == 1)
        {
            $cids = array($cid);
            $cids = array_merge($cids,$categorydata->GetSubCategoryIDs($cid));            
            $cids = implode(',', $cids);
            if($all)
            {
                return $yiqi_db->get_results(CheckSql("select * from yiqi_product where cid in ($cids) order by $orderby limit $skip,$take "));
            }
            else
            {
                return $yiqi_db->get_results(CheckSql(sprintf("select * from yiqi_product where cid in ($cids) and adddate <= '%s' order by $orderby limit $skip,$take",date("Y-m-d H:i:s"))));
            }
        }
        else
        {
            if($all)
            {
                return $yiqi_db->get_results(CheckSql("select * from yiqi_product order by $orderby"));
            }
            else
            {
                return $yiqi_db->get_results(CheckSql(sprintf("select * from yiqi_product where adddate <= '%s' order by $orderby",date("Y-m-d H:i:s"))));
            }
        }
    }
    

2.模板文件中如何调用:

{assign var="productlist" value=$productdata->GetProductList(3,0,5,"adddate desc")}
    {foreach from=$productlist item=subcateinfo}
       <li> 
         <a href="{formaturl type="product" siteurl=$siteurl name=$subcateinfo->filename}">{$subcateinfo->name}</a>
       </li>
 {/foreach}  
GetProductList(3,0,5,"adddate desc")参数说明:GetProductList(分类id,跳跃个数,输出个数,"adddate desc")
注:所有的标签函数都是可以修改的!
posted @ 2014-06-24 09:42  李腾  阅读(671)  评论(0编辑  收藏  举报

如果我加了黑链呢:http://liteng.org