Emlog按天数调用热门文章和随机文章列表完整教程

    • 内容
    • 相关

    一、效果图

    二、代码部署

    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']); ?>" title="<?php echo $row['title']; ?>"><span>热</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']); ?>" title="<?php echo $row['title']; ?>"><span>荐</span><?php echo $row['title']; ?></a></li>
    <?php } ?>
    <?php } ?>

    2、打开当前模板下的“log_list.php”文件 把下面代码添加到要显示的地方即可

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

    3、在style.css文件中加入以下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:10px;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;}

     

    每日打开支付宝首页搜“1056355”领红包

    有好的文章或资源希望【唯品乐淘】帮助分享推广,猛戳这里我要投稿

  • 本文标签:

    版权说明:本文为转载文章,源自互联网,由本站整编
    原文地址: https://www.junyao2018.cn/post-204.html

    本文链接:Emlog按天数调用热门文章和随机文章列表完整教程 - https://www.vipletao.cn/post-4223.html

    发表评论

    电子邮件地址不会被公开。 必填项已用*标注

    未显示?请点击刷新