echsop根据调用文章分类ID获取用户最新添加的文章与文章置顶特殊显示

调取文章,一般用两种方法,一种是后台中设置模板直接调用,简单便捷;另一种是通过代码调用。而下面我们要讲的是通过代码进行调用。

简单举个例子,之前做一个客户模板修改,是调用多个文章分类。我把内容部分拿到一个新建的库文件里边

<div id="con_three_1" style="display: block;"> <?php $GLOBALS[‘smarty’]->assign(‘articles’,index_get_class_articles(23, 19)); <!–调取最新文章列表,23代表文章分类id,19为数量–>?> <div class="ttkx"> <ul class="t1b"> <?php $index=0; ?> <!–{foreach from=$articles item=art name=art}–> {if $art.article_type eq 1 }<!–置顶文章特殊显示–> {if $index <1 } <?php $index=$index+1; $GLOBALS[‘smarty’]->assign(‘index’,$index); ?> <li class="li1"> <a title="{$art.title}" target="_blank" href="{$art.url}"> <img src="{$art.file_url}"></img> <h2>{$art.short_title}</h2> <p></p> </a> </li> {/if} {/if} <!–{/foreach}–> </ul> <ul class="tul2"><!–{foreach from=$articles item=art name=art}–> {if $smarty.foreach.art.iteration>1} <li>

<span>

{$art.add_time}

</span> <a title="{$art.title}" {if $art.article_type eq 1} style="color:#F00" {/if} target="_blank" href="{$art.url}">{$art.short_title}</a><!–如果是置顶文章则文字显示为红色–>

</li> {/if} <!–{/foreach}–> </ul> </div>

</div>

因为模板设置的是一个鼠标划过切换效果,所以这里就简单的展示一下。

然后找到模板根目录下的includes文件夹找到init.php文件,在最后添加一下代码

function index_get_class_articles($cat_aid, $cat_num)

{

$sql = "SELECT article_id, title,open_type,cat_id,content,file_url,add_time, keywords,article_type, description FROM " .$GLOBALS[‘ecs’]->table(‘article’). " WHERE cat_id = ".$cat_aid." and is_open = 1 "." ORDER BY article_id desc "." LIMIT " . $cat_num;//这里设置的根据文章ID降序显示,则用户新添加的文章就自然而然的显示在前面了

$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][‘keywords’] = $row[‘keywords’];$arr[$idx][‘article_type’] = $row[‘article_type’];$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][‘content’] = $row[‘content’];

$arr[$idx][‘short_content’] = sub_str($row[‘content’],33);

$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’]));

$arr[$idx][‘file_url’] = trim($row[‘file_url’]); //文章图片路径

$arr[$idx][‘description’] = $row[‘description’];

$arr[$idx][‘short_description’] = sub_str($row[‘description’],15);

}

return $arr;

}

,你的脸是为了呈现上帝赐给人类最贵重的礼物–微笑,

echsop根据调用文章分类ID获取用户最新添加的文章与文章置顶特殊显示

相关文章:

你感兴趣的文章:

标签云: