Emlog非插件实现文章添加相关文章的方法-站长杂谈下载

Emlog非插件实现文章添加相关文章的方法

来自版块: 站长杂谈发表于: 2015-8-17 13:05:50
46839
0
如本资源下载地址失效,请点击此处进行反馈
开通本站Svip会员,全站资源免费下
Emlog非插件实现文章添加相关文章的方法
: w) a$ A, V: ?8 Q+ B/ @1 P第一步:在模板文件module.php中加入以下代码
  1. <?php# G: ]; c# z8 M4 \
  2. //文章详情页下相关文章7 q) p& P! J9 f1 O5 \
  3. function xg_logs($logData = array()){
      Y7 U; g9 N, s$ q" t
  4. if (is_file($configfile)) {require $configfile;}else{
    2 A4 s3 C& _# `* A$ |2 d# J
  5. $related_log_type = 'sort';//相关日志类型,sort为分类,tag为标签- I6 w9 X9 N( W$ B2 Q1 o& _1 K
  6. $related_log_sort = 'views_desc';//排列方式,views_desc 为点击数(降序)comnum_desc 为评论数(降序) rand 为随机 views_asc 为点击数(升序)comnum_asc 为评论数(升序)
    2 k5 w4 W/ Y& P
  7. $related_log_num = '10'; //显示文章数8 h7 h2 J; N1 @7 I' H, `
  8. $related_inrss = 'y'; //是否显示在rss订阅中,y为是,其它值为否
    , U+ M* r9 w' o  C
  9. }global $value;$DB = MySql::getInstance();$CACHE = Cache::getInstance();extract($logData);if($value)0 w# {7 h) P; ]; `+ P
  10. {$logid = $value['id'];$sortid = $value['sortid'];global $abstract;}
    8 o! Z8 `; u+ }; ~, ^; G3 g; Z9 R9 c) |
  11. $sql = "SELECT gid,title FROM ".DB_PREFIX."blog WHERE hide='n' AND type='blog'";
    - u3 e/ E! d8 Q; @/ {0 `6 v, @. f0 i' j
  12. if($related_log_type == 'tag'){$log_cache_tags = $CACHE->readCache('logtags');$Tag_Model = new Tag_Model();$related_log_id_str = '0';foreach($log_cache_tags[$logid] as $key => $val){$related_log_id_str .= ','.$Tag_Model->getTagByName($val['tagname']);}! y5 P+ F% h- Z. D
  13. $sql .= " AND gid!=$logid AND gid IN ($related_log_id_str)";}else{
    " S) n. W7 B6 {4 A& g* a
  14. $sql .= " AND gid!=$logid AND sortid=$sortid";}' V  b- C$ V  _; {
  15. switch ($related_log_sort){case 'views_desc':{2 `  I, y% J' X; z: l# H
  16. $sql .= " ORDER BY views DESC";break;}case 'views_asc':{
    ( Q2 U" m9 }7 K4 m5 Y
  17. $sql .= " ORDER BY views ASC";break;}case 'comnum_desc':{
    $ C4 j$ J) [. m  J
  18. $sql .= " ORDER BY comnum DESC";break;}case 'comnum_asc':{2 k% W  u, _, o" @( u$ I
  19. $sql .= " ORDER BY comnum ASC";break;}case 'rand':{, x% F9 R; k! Q) e5 G
  20. $sql .= " ORDER BY rand()";break;}}7 C6 `) B: R2 n" x
  21. $sql .= " LIMIT 0,$related_log_num";
    ; ^* R" R4 S% R+ I& ]( ^
  22. $related_logs = array();$query = $DB->query($sql);while($row = $DB->fetch_array($query))/ m) N1 `; f9 I. ?
  23. {$row['gid'] = intval($row['gid']);$row['title'] = htmlspecialchars($row['title']);$related_logs[] = $row;}
    4 ~4 H+ g9 o* R
  24. $out = '';if(!empty($related_logs)){foreach($related_logs as $val){
    : [0 x( r8 ]( ]& P& ^3 C, Y) A4 t! F1 b
  25. $out .= "<li><a href="".Url::log($val['gid'])."" title="{$val['title']}">{$val['title']}</a></li>";* I0 ^: W' a9 T" K
  26. }}if(!empty($value['content'])){if($related_inrss == 'y'){$abstract .= $out;}}else{echo $out;}}
    . A3 w0 F- H$ A+ A, {
  27. ?>
复制代码
第二步:在模板文件echo_log.php的适合位置放入<?php xg_logs($logData);?>,最后写上CSS格式就ok了

全部评论 0

您需要登录后才可以回帖 立即登录
登录
0
0
0
返回顶部