目前在修改更新别人制作的仿小米mi2的emlog主题,由于没有独立自主制作过emlog模板,所以对emlog的模板标签及一系列相关代码不了解,也不熟悉,刚好想要实现emlog日志页面的相关文章效果,谷歌搜索下找到了相关代码。代码比较长,对于仅想要效果的博主就不需要深入研究,知道怎么添加就行了。
添加步骤:
- 在当前主题module.php文件中添加如下代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
<?php function related_logs($logData = array()) { $configfile = EMLOG_ROOT.'/content/plugins/related_log/related_log_config.php'; if (is_file($configfile)) { require $configfile; }else{ $related_log_type = 'sort';//相关日志类型,sort为分类,tag为日志; $related_log_sort = 'rand';//排列方式,views_desc 为点击数(降序)comnum_desc 为评论数(降序) rand 为随机 views_asc 为点击数(升序)comnum_asc 为评论数(升序) $related_log_num = '10'; //显示文章数,排版需要,只能为10 $related_inrss = 'y'; //是否显示在rss订阅中,y为是,其它值为否 } global $value; $DB = mysql::getInstance(); $CACHE = Cache::getInstance(); extract($logData); if($value) { $logid = $value['id']; $sortid = $value['sortid']; global $abstract; } $sql = "SELECT gid,title FROM ".DB_PREFIX."blog WHERE hide='n' AND type='blog'"; 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']); } $sql .= " AND gid!=$logid AND gid IN ($related_log_id_str)"; }else{ $sql .= " AND gid!=$logid AND sortid=$sortid"; } switch ($related_log_sort) { case 'views_desc': { $sql .= " ORDER BY views DESC"; break; } case 'views_asc': { $sql .= " ORDER BY views ASC"; break; } case 'comnum_desc': { $sql .= " ORDER BY comnum DESC"; break; } case 'comnum_asc': { $sql .= " ORDER BY comnum ASC"; break; } case 'rand': { $sql .= " ORDER BY rand()"; break; } } $sql .= " LIMIT 0,$related_log_num"; $related_logs = array(); $query = $DB->query($sql); while($row = $DB->fetch_array($query)) { $row['gid'] = intval($row['gid']); $row['title'] = htmlspecialchars($row['title']); $related_logs[] = $row; } $out = ''; if(!empty($related_logs)) { foreach($related_logs as $val) { $out .= "<li><a href=\"".Url::log($val['gid'])."\">{$val['title']}</a></li>"; } } if(!empty($value['content'])) { if($related_inrss == 'y') { $abstract .= $out; } }else{ echo $out; } } ?>
- 打开当前主题的echo_log.php文件,在喜欢的位置,如<?php echo $log_content; ?>下面添加调用代码
1 2 3 4 5 6
<div id="art_about"> <b>也许你还会对下面的内容感兴趣:</b> <ul class="art_col"> <?php related_logs($logData);?> </ul> </div>
- 然后通过css美化样式,下面是博客吧设计的显示样式,供需要的博主作参考
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#art_about{margin:10px 5px; padding: 10px 0; overflow:hidden; padding-bottom:10px;} #art_about b{margin:0 0px 5px 10px} #art_about ul{padding:10px;} #art_about ul li { line-height:1.5em; float:left; background:url("images/dot.gif") no-repeat scroll 0px 50% transparent; padding-left:15px; margin:5px 15px; width:350px; white-sapce:nowrap; overflow:hidden; display:inline; }
代码摘自互联网
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。