1.因为文章是通过new_articles.lbi里面控制的。所以由里面的代码得知数据是通过new_articles来传递的。在index.php搜索 new_articles。
2.找到了这个  $smarty->assign('new_articles',    index_get_new_articles());   // 最新文章
3.在寻找index_get_new_articles()这个方法,同样是在index.php里面
function index_get_new_articles()
{
    $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' .
            ' ORDER BY a.article_type DESC, a.add_time DESC LIMIT ' . $GLOBALS['_CFG']['article_number'];
    $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']);
      
        $arr[$idx]['cat_id']      = $row['cat_id'];
    }

    return $arr;
}
加了上面一句代码。
4.回到new_articles.lbi
<!--{foreach from=$new_articles item=article}-->
    <!--{if $article.cat_id == 4}-->
  <li>
    [<a href="{$article.cat_url}">{$article.cat_name}</a>] <a href="{$article.url}" title="{$article.title"escape:html}">{$article.short_title|truncate:10:"...":true}</a>
    <span>{$article.add_time}</span>
    </li>
     <!--{/if}-->
<!--{/foreach}-->
加一个判断就全部搞定了!!!想读哪个栏目就读哪个栏目了。

 

转发请注明:丁丁猫

猜你喜欢