ECShop在任何页面调用最新文章并变成随机文章

一、让最新文章变成随机文章

 

在根目录 打开index.php文件

查找代码 ' ORDER BY a.article_type DESC, a.add_time DESC LIMIT ' . $GLOBALS['_CFG']['article_number'];

将它修改为 ' ORDER BY RAND() LIMIT ‘ . $GLOBALS['_CFG']['article_number'];

 

 

 

二、在全站显视最新文章

 

把以下代码保存为文件 new_articles_ec.lbi 

<?php
$GLOBALS['smarty']->assign(‘new_articles’,    index_get_new_articles());
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']);
}

return $arr;
}
?>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<div>
<h2>最新文章</h2>
<div>
<!– {if $new_articles} –>
<!– {foreach name=new_articles from=$new_articles item=article} –>
<!– {if $smarty.foreach.new_articles.index lt 8} 限制文章显示数量 –>
<a href=”{$article.url}” title=”{$article.title|escape:html}”>{$article.short_title|truncate:30}</a><br />
<!– {/if} –>
<!–{/foreach}–>
<!–{else}–>
当前没有最新文章!
<!– {/if} –>
</div>
</div>

再把这个文件上传到模板文件的 library 目录下。

 

再在你需要显视文章的位置加入以下代码

<!– #BeginLibraryItem “/library/new_articles_ec.lbi” –><!– #EndLibraryItem –>

 

如果你修改了第一步,那显视的是随机文章,如果没有修改,那就是最新文章。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值