ecshop 小修改

php

2013-07-12 21:38

主页  index.php

 $smarty->assign('listnews', index_get_fenlei_id(4));

//$ac_id_list=index_get_fenlei_id(4);
//print_r($ac_id_list);

// $smarty->assign('ac_id_list', $ac_id_list);

 

 

主页模板文件插入  themes/模板/index.dwt  

  <!-- #BeginLibraryItem "/library/listnews.lbi" --><!-- #EndLibraryItem -->

 

创建 themes/模板/library/listnews.lbi

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<div class="c2ff_1">

<!--{foreach from=$listnews item=article_item}-->

<div class="dkk_1">

<div  class="xkk_1">  <span><a href="{$article_item.url}">更多>></a></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="{$article_item.url}">{$article_item.cat_name}</a>   </div>

<ul>

<!--{foreach from=$article_item.list item=article_item2}-->

<li> <span>·</span> <a href="{$article_item2.url}">{$article_item2.title|truncate:14:"...":true}</a></li>

 <!--{/foreach}-->

 </ul>

</div>

  <!--{/foreach}-->

</div>

<div style="clear:both; height:20px;"></div>


创建 themes/模板/style.css

.c2ff_1{ width:990px; height:auto; background-color:#000}

.dkk_1{width:240px; height:200px; float:left; border:#CCC 1px solid; margin-top:5px; margin-right:3px; margin-left:2px}

.dkk_1 ul{width:240px;  float:left;  margin:0; padding:0; clear:both;}

.dkk_1 ul li{ margin-left:15px;  background:url(/themes/68ecshopcom_yhscfree/images/xx.jpg) no-repeat bottom; width:215px; height:29px; line-height:29px;}

.dkk_1 ul li span{ color:#f98703;}

.xkk_1{width:240px; height:27px; line-height:28px; float:left; background-color:#f98703; }

.xkk_1 span{ height:20px; float: right;  margin-right:15px;}

.xkk_1 a{ color:#FFF;}


 

根目录:admin\includes\lib_template.php

模板库文件声明和定义->\admin\includes\lib_template.php,每个模板允许设置的库项目

  'index' => array( 下添加

'/library/listnews.lbi' => 8,   这里是要显示的文章数量

 

文件\languages\zh_cn\admin\template.php

$_LANG['template_libs'][listnews] = '我的库项目';
当然英文的也可以加


 

 

自建函数----------------------------------------------------------------------------

/**
 * 获得分类下的ID和名字。
 *
 * @access  private
 * @return  array
 */
function index_get_fenlei_id($id,$f=8)
{
$ar=array();
$id=4;
$sql = 'SELECT cat_id,cat_name FROM '. $GLOBALS['ecs']->table('article_cat').' where parent_id ='.$id.' ORDER BY `sort_order` DESC ,cat_id  desc LIMIT 0 , '.$f; 
    $res = $GLOBALS['db']->getAll($sql);

    $arr = array();
    foreach ($res AS $idx => $row)
    {
  $ar=array();
       $ar[cat_id] = $row[cat_id];
    $ar[cat_name] = $row[cat_name];
    $ar[url] = "article_cat.php?id=".$row[cat_id];
   
    $ar['list']=index_get_fenlei_list($row[cat_id]);
      $arr[]=$ar;
    }

    return $arr;
}


/**
 * 获得分类下文章 *
 * @access  private
 * @return  array
 */
function index_get_fenlei_list($id)
{
 $sql = 'SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type, ac.cat_id, ac.cat_name ' .
            ' FROM ' . $GLOBALS['ecs']->table('article') . ' AS a, ' .
                $GLOBALS['ecs']->table('article_cat') . ' AS ac' .
            ' WHERE  a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1 and ac.cat_id='.$id .
            ' ORDER BY a.article_type DESC, a.add_time DESC LIMIT 0,' . get_librany_number('listnews');
    $res = $GLOBALS['db']->getAll($sql);

    $arr = array();
    foreach ($res AS $idx => $row)
    {
        $arr[$idx]['id']          = $row['article_id'];
        $arr[$idx]['title']       = $row['title'];
        $arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?
                                        sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];
        $arr[$idx]['cat_name']    = $row['cat_name'];
        $arr[$idx]['add_time']    = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
        $arr[$idx]['url']         = $row['open_type'] != 1 ?
                                        build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);
        $arr[$idx]['cat_url']     = build_uri('article_cat', array('acid' => $row['cat_id']), $row['cat_name']);
    }

    return $arr;
}