EMLOG按天数调用热门与随机文章

分享

IMG_20200808_050524.jpg

这个是从fee模板扒下来的,我看到一些网站也发过但是不完整,没有CSS文件,现在我就全部分享出来。

修改方法

1、在module.php文件中加入如下的代码:
<?php
//30天按点击率排行文章
function getdatelogs($log_num) {
$db = MySql::getInstance();
$time = time();
$sql = "SELECT gid,title,comnum FROM ".DB_PREFIX."blog WHERE type='blog' AND date > $time - 30*24*60*60 ORDER BY `views` DESC LIMIT 0,$log_num";
$list = $db->query($sql);
while($row = $db->fetch_array($list)){ ?>
<li class="layout_li"><strong>[评论 <?php echo $row['comnum']; ?>]</strong><a href="<?php echo Url::log($row['gid']); ?>" rel="external nofollow"  rel="external nofollow"  title="<?php echo $row['title']; ?>"><span><?php echo ++$i;?></span><?php echo $row['title']; ?></a></li>
<?php } ?>
<?php } ?>
<?php
//随机文章
function getRandLog($log_num) {
$db = MySql::getInstance();
$sql = "SELECT gid,title,comnum FROM ".DB_PREFIX."blog WHERE type='blog' and hide='n' ORDER BY rand() LIMIT 0,$log_num";
$list = $db->query($sql);
while($row = $db->fetch_array($list)){ ?>
<li class="layout_li"><strong>[<?php echo gettime($row['gid']);?>]</strong><a href="<?php echo Url::log($row['gid']); ?>" rel="external nofollow"  rel="external nofollow"  title="<?php echo $row['title']; ?>"><span>荐</span><?php echo $row['title']; ?></a></li>
<?php } ?>
<?php } ?>

2、调用代码;我的主题的首页文件是log_list.php,如果你的不是这个文件就看看有没有index.php这个文件。把如下代码加进去。

<!-- 热门文章-->
		<section class="hot_posts">
		<div class="suiji">
			<h3>随机文章</h3>
			<ul>
			<?php getRandLog(6);?>
			</ul>
		</div>
		<div class="hots">
			<h3>本月热门</h3>
			<ul>
			<?php getdatelogs(6);?>
			</ul>
		</div>
		</section>

3、将如下CSS代码加到全局文件,例如style.css或者main.css,具体看你的模板。

.hot_posts {
 background-color:#fff;
 padding:20px;
 position:relative;
 font-size:0;
 box-shadow:0 0px 20px rgba(160, 160, 160, 0.1);
 border-radius:1px;
 border: 1px solid #e5e5e5;
 margin-bottom: 10px;
}
.hot_posts .suiji {
 display:inline-block;
 vertical-align:top;
 width:50%;
 padding-right:10px;
}
.hot_posts .hots {
 display:inline-block;
 vertical-align:top;
 width:50%;
 padding-left:10px;
}
.hot_posts h3 {
 border-bottom:2px #f2f2f2 solid;
 padding-bottom:6px;
 margin-bottom:8px;
 font-size:16px;
 margin-top:0;
 position:relative;
}
.hot_posts h3:after {
 content:"";
 color:#ffffff;
 position:absolute;
 height:2px;
 width:30px;
 background:#45b6f7;
 left:0;
 bottom:-2px;
 -webkit-transition:all .25s ease-in;
 -moz-transition:all .25s ease-in;
 transition:all .25s ease-in;
}
.hot_posts .suiji:hover h3:after,
.hot_posts .hots:hover h3:after {
 width:100px;
}
.hot_posts ul {
 padding:0
}
.hot_posts ul li {
 display:block;
 padding:8px 0;
 -webkit-transition:ease-in-out 0.25s;
 transition:ease-in-out 0.25s;
 font-size:12px;
}
.hot_posts ul li:hover {
 font-size:15px;
 -webkit-transition:ease-in-out 0.25s;
 transition:ease-in-out 0.25s;
}
.hot_posts ul li a {
 display:block;
 -ms-text-overflow:ellipsis;
 text-overflow:ellipsis;
 white-space:nowrap;
 overflow:hidden;
 line-height:22px;
}
.hot_posts ul li strong {
 float:right;
 font-weight:normal;
 line-height:22px;
 padding-left:15px;
}
.hot_posts ul li a>img {
 width:30px;
 height:22px;
 margin-right:4px;
 border-radius:5px;
 vertical-align:bottom;
}
.hot_posts span {
 width:22px;
 height:22px;
 background-color:#f2f2f2;
 display:inline-block;
 text-align:center;
 margin-right:4px;
 border-radius:25px;
 line-height:22px;
 color:#666;
}
.hot_posts ul li:nth-child(1) span {
 background-color:#ff5a3c;
 color:#fff;
}
.hot_posts ul li:nth-child(2) span {
 background-color:#13b755;
 color:#fff;
}
.hot_posts ul li:nth-child(3) span {
 background-color:#00a9e3;
 color:#fff;
}
@media screen and (max-width: 768px) {
 .hot_posts .suiji {
  width:100%;
  margin-bottom:20px;
 }
 .hot_posts .hots {
  width:100%;
  padding-left:0;
 }
}
最后刷新缓存就可以实现了,我个人感觉也非常好看!
提示信息

SQL语句执行错误: SELECT * from emlog_attachment_web where logid = 702
Table 's7937350.emlog_attachment_web' doesn't exist

«点击返回