emlog默认主题的侧栏模块“最新评论”不显示评论文章标题和评论时间,部分用户会有显示评论所属文章的标题以及该评论的评论时间的需求,可在emlog wiki中查找没有发现相关的调用函数代码,不过可以使用sql语句通过评论gid进行查询实现调用,下面博客吧通过emlog默认主题进行修改。
查询函数代码:(把下面的代码添加到主题的module.php文件)
1 2 3 4 5 6 7 8 9 10 11 12 |
function cutome_call($gid,$type){ $db = MySql::getInstance(); $sql = "SELECT * FROM ".DB_PREFIX."blog WHERE hide='n' and gid in ($gid) ORDER BY `date` DESC LIMIT 0,1"; $list = $db->query($sql); while($row = $db->fetch_array($list)){ if($type=='title'){ return $row['title']; }elseif($type == 'time'){ return $row['date']; } } } |
找到主题最新评论代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php //widget:最新评论 function widget_newcomm($title){ global $CACHE; $com_cache = $CACHE->readCache('comment'); ?> <li> <h3><span><?php echo $title; ?></span></h3> <ul id="newcomment"> <?php foreach($com_cache as $value): $url = Url::comment($value['gid'], $value['page'], $value['cid']); ?> <li id="comment"><?php echo $value['name']; ?> <br /><a href="<?php echo $url; ?>"><?php echo $value['content']; ?></a></li> <?php endforeach; ?> </ul> </li> <?php }?> |
修改后的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php //widget:最新评论 function widget_newcomm($title){ global $CACHE; $com_cache = $CACHE->readCache('comment'); ?> <li> <h3><span><?php echo $title; ?></span></h3> <ul id="newcomment"> <?php foreach($com_cache as $value): $url = Url::comment($value['gid'], $value['page'], $value['cid']); ?> <li id="comment"> <?php echo $value['name']; ?> <?php echo gmdate('Y-n-j',cutome_call($value['gid'],'time'));?> <br /><a href="<?php echo $url; ?>" title="<?php echo cutome_call($value['gid'],'title');?>"><?php echo $value['content']; ?></a> </li> <?php endforeach; ?> </ul> </li> <?php }?> |
代码中的以下代码是评论时间:
1 |
<?php echo gmdate('Y-n-j',cutome_call($value['gid'],'time'));?> |
代码中的以下代码是评论标题:
1 |
<?php echo cutome_call($value['gid'],'title');?> |
原创文章,作者:carmelaweatherly,如若转载,请注明出处:https://blog.ytso.com/248150.html