A-A+

ecshop 系统文章进行随机显示

2015年09月02日 PHP开源系统 评论 2 条 阅读 124 views 次

使ecshop系统文章频道进行随机化的显示,这个想法得以于我对 sql 的进一步研究,在 php 中读取 sql 而显示文章的内容,而进行文章的排序有多种方法,比如 order by id desc,order by id asc 等,当然更为复杂一些的还有以 time 为排序的方式,在 ecshop 中就是按照时间的更新顺序来排序的,而随机显示则是将 php 随机函数 rand() 进行整合过来了,随机读取的 sql 语句如 ORDER BY rand(),只要将之前的顺序 sql 更改为随机 rand 就可以实现其随机显示了,这种方法不仅仅可以应用到 ecshop 当中,任何程序中都可以。

在这里,夏日博客将把详细的 ecshop 中文章部分进行随机显示,如下:

先修改后台:

找到ecshop的添加文档,admin/article.php文件,找到288行:

  1. if ($exc->edit("title='$_POST[title]', cat_id='$_POST[article_cat]', article_type='$_POST
  2. [article_type]', is_open='$_POST[is_open]', author='$_POST[author]', author_email='$_POST
  3. [author_email]', keywords ='$_POST[keywords]', file_url ='$file_url', open_type='$open_type',
  4. content='$_POST[FCKeditor1]', link='$_POST[link_url]', description = '$_POST[description]'"$_POST
  5. ['id']))

修改成:

  1. $add_time = gmtime();
  2. if ($exc->edit("title='$_POST[title]', add_time='$add_time',cat_id='$_POST[article_cat]',
  3. article_type='$_POST[article_type]', is_open='$_POST[is_open]', author='$_POST[author]',
  4. author_email='$_POST[author_email]', keywords ='$_POST[keywords]', file_url ='$file_url',
  5. open_type='$open_type', content='$_POST[FCKeditor1]', link='$_POST[link_url]', description = '$_POST
  6. [description]'"$_POST['id']))

再找到includes/lib_article.php找到48与56行把' ORDER BY article_type DESC, article_id DESC';修改成' ORDER BY article_type DESC, add_time DESC';

根据更新时间进行排序并不是我所需要的,但却给了我一个非常重要的提示。非常简单的修改串代码让ecshop文章实现随机展示找到includes/lib_article.php找到48与56行把' ORDER BY article_type DESC, article_id DESC';

修改成:

' ORDER BY rand()';

注意是两处!就这么简单就完成,每次更新缓存,文章的排序就会改变一次。

标签:

2 条留言  访客:2 条  博主:0 条

  1. 方块君

    夏日大大,希望你紧急加q群100929595给迷茫的菜鸟带来希望

    • smiling

      已经添加。。。

给我留言