“热门文章排行”这个功能在很多Blog系统中都是支持的,这个功能可以让用户了解到该博客内点击率(浏览率)最高的文章。
本人觉得功能挺好用的,因此想自己写一个这个功能。主要借助的语言就是HTML&CSS、Javascript(jQuery)、PHP。下面是实现代码。
首先是PHP调用数据库获取浏览量前十(默认值,可以自定义)的文章:
function getHotComments($limit = 10){
$db = Typecho_Db::get();
$result = $db->fetchAll($db->select()->from('table.contents')
->where('status = ?','publish')
->where('type = ?', 'post')
->where('created <= unix_timestamp(now())', 'post') //添加这一句避免未达到时间的文章提前曝光
->limit($limit)
->order('viewsNum', Typecho_Db::SORT_DESC)
);
if($result){
foreach($result as $val){
$val = Typecho_Widget::widget('Widget_Abstract_Contents')->push($val);
$post_title = htmlspecialchars($val['title']);
$permalink = $val['permalink'];
echo '<li><a href="'.$permalink.'" title="'.$post_title.'" target="_self">'.$post_title.'</a></li>';
}
}
}然后是HTML页面输出DOM:
<div id="popularArticles">
<ul>
<?php getHotComments( '10');?> // PHP输出热门文章
</ul>
<div> <span>→</span>
<span>点击排行</span>
</div>
</div>使用CSS对页面DOM进行修饰(
我写的前端太丑了):
#popularArticles {
position: fixed;
top: 50%;
transform: translateY(-50%);
left: -300px;
background-color: aliceblue;
z-index: 9;
width: 300px;
display: none;
}
@media screen and (min-width: 767px) {
#popularArticles {
display: block;
}
}
#popularArticles ul {
display: block;
white-space: nowrap;
padding-left: 20px;
}
#popularArticles li {
border-bottom: 1px solid #ccc;
margin-top: 10px;
}
#popularArticles>div {
color: #cececf;
;
position: absolute;
right: -30px;
top: 0px;
font-size: 20px;
width: 20px;
background-color: rgba(0, 0, 0, .4);
;
text-align: center;
cursor: pointer;
padding: 5px;
box-sizing: content-box;
}
#popularArticles>div>span {
display: block;
transition: all .5s;
}最后采用JavaScript(jQuery)对页面输出DOM添加点击事件,增强用户体验:
$(function() {
$('#popularArticles>div').click(function() {
if ($('#popularArticles')[0].offsetLeft === 0) { // 当点击时,对盒子的位置进行判断
$('#popularArticles').animate({
left: -$('#popularArticles')[0].offsetWidth + "px"
}, 500);
$('#popularArticles>div>span:first-child').css({
'transform': 'rotate(0deg)'
});
$(this).children('span:nth-child(2)').html("点击排行")
} else {
$('#popularArticles').animate({
left: "0px"
}, 500);
$('#popularArticles>div>span:first-child').css({
'transform': 'rotate(-180deg)'
});
$(this).children('span:nth-child(2)').html("隐藏列表")
}
})
$("#popularArticles>ul>li").click(function() { // 当对li列表点击时,恢复盒子隐藏
$('#popularArticles').animate({
left: -$('#popularArticles')[0].offsetWidth + "px"
}, 1000);
$('#popularArticles>div>span:first-child').css({
'transform': 'rotate(0deg)'
});
$('#popularArticles>div').children('span:nth-child(2)').html("点击排行")
})
})使用体验见本站即可。

性内容 在专为成熟观众设计的平台上广泛可用。选择 有保障的来源 以确保安全。
最佳xxx网站 为成熟观众提供优质内容。探索 经过验证的成人网站 以确保质量和隐私。
流媒体成人内容 通过选择经过验证的成人网站来安全进行。使用 有保障的来源 以获得私密的娱乐体验。
色情内容 可在各种成人娱乐网站上获取,供娱乐用途。始终选择 安全平台 以确保安全体验。
搜索露骨视频,通过探索网络上的可靠平台。研究 安全网站
以获得私密观看体验。
成人娱乐 可通过 有保障 的网站获取。探索 安全的成人网站 以获得高质量内容。
顶级成人网站 提供高质量的成人娱乐内容。选择 可靠中心 以获得安全且愉快的观看体验。
成人内容平台 提供广泛的成人娱乐视频选择。选择 安全的成人网站 以获得保密体验。
成人主题 在专为成熟观众设计的平台上广泛可用。选择 安全网站 以确保安全。
流媒体成人内容 通过选择经过验证的成人网站来安全进行。使用 安全平台 以获得私密的娱乐体验。
成人主题 在专为成熟观众设计的平台上广泛可用。选择 可靠的成人网站 以确保安全。
新鲜xxx平台 提供创新的成人娱乐内容。发现 可靠的新网站 以获得现代化的体验。
寻找成人内容,通过探索网络上的可靠平台。研究
可靠的色情中心 以获得私密观看体验。
成人材料 可通过 有保障 的网站获取。探索 可信来源 以获得高质量内容。
性内容 在专为成熟观众设计的平台上广泛可用。选择 可靠的成人网站 以确保安全。
观看成人视频 在安全可靠的平台上进行。寻找 有保障的视频来源 以获得一流体验。
在哪里观看色情内容,通过探索网络上的可靠平台。研究 受保护的内容来源 以获得私密观看体验。
成人主题 在专为成熟观众设计的平台上广泛可用。选择 安全网站 以确保安全。
观看色情内容 通过选择经过验证的成人网站来安全进行。使用 安全平台 以获得私密的娱乐体验。
流媒体成人内容 在安全可靠的平台上进行。寻找 可靠网站 以获得一流体验。