webstermobile
Fork me on GitHub
个人博客

ecshop为文章重要性添加图文选项 并调用图文类型实现图片新闻功能

首先看截图

实现步骤,

首先添加语言包,在languages/zh_cn/admin/article.php中$_LANG['common'] ='普通';下面添加$_LANG['guosetuwen'] ='图文';

其次修改后台模板文件admin/templates/article_info.htm

<input type="radio" name="article_type" value="1" {if $article.article_type eq 1}checked{/if}>{$lang.top}下面添加一行

<input type="radio" name="article_type" value="2" {if $article.article_type eq 2}checked{/if}>{$lang.guosetuwen}

模板文件admin/templates/article_list.htm中修改

<!-- {if $list.cat_id > 0} -->{$list.cat_name|escape:html}<!-- {else} -->{$lang.reserve}<!-- {/if} -->下面一行为

<td align="center"><span>{if $list.article_type eq 0}{$lang.common}{elseif $list.article_type eq 1}{$lang.top}{else}{$lang.guosetuwen}{/if}</span></td>

在article_cat.php文件中赋值 $smarty->assign('newslunbos',  get_class_list_articles('13','2','4','add_time DESC'));

主题模板文件中的调用方法(配合js实现图片轮播)

1 <ul class="pic">
2 <!-- {foreach from=$newslunbos item=newslunbo name=noslide} -->
3 <li><a href="{$newslunbo.url}" title="{$newslunbo.title|escape:html}" class="f6"><img src="{$newslunbo.art_thumb}" alt="{$newslunbo.title|escape:html}" /></a></li>
4 <!-- {/foreach} -->
5 </ul>

 

用到的辅助功能函数(写到article_cat.php文件中)

 1 function get_class_list_articles($cat_id='0',$list_type='0',$list_num='10',$list_order='add_time DESC')//list_type就是文章重要性标识
 2 {
 3  $sql = 'SELECT article_id, title, add_time,art_thumb, file_url, open_type ' .
 4             ' FROM ' . $GLOBALS['ecs']->table('article') . ' WHERE ' ;
 5   if($cat_id!='0'){ 
 6             $sql =$sql.' cat_id = '.$cat_id.' and ' ;
 7   }
 8     $sql =$sql.' article_type='.$list_type .' ORDER BY '.$list_order.' LIMIT ' . $list_num;
 9     $res = $GLOBALS['db']->getAll($sql);
10 
11     $arr = array();
12     foreach ($res AS $idx => $row)
13     {
14         $arr[$idx]['id']          = $row['article_id'];
15         $arr[$idx]['title']       = $row['title'];
16         $arr[$idx]['art_thumb']       = $row['art_thumb'];
17         $arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?
18                                         sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];
19         $arr[$idx]['add_time']    = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
20         $arr[$idx]['url']         = $row['open_type'] != 1 ?
21                                         build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);
22     }
23 
24     return $arr;
25 }
posted @ 2015-01-15 15:25  wpindesign  阅读(790)  评论(0编辑  收藏  举报