心知天气
在/usr/themes/handsome/component/headnav.php
文件内第103行,搜索框前面添加如下代码
<!-- 知心天气-->
<div id="tp-weather-widget" class="navbar-form navbar-form-sm navbar-left shift"></div>
<script>(function(T,h,i,n,k,P,a,g,e){g=function(){P=h.createElement(i);a=h.getElementsByTagName(i)[0];P.src=k;P.charset="utf-8";P.async=1;a.parentNode.insertBefore(P,a)};T["ThinkPageWeatherWidgetObject"]=n;T[n]||(T[n]=function(){(T[n].q=T[n].q||[]).push(arguments)});T[n].l=+new Date();if(T.attachEvent){T.attachEvent("onload",g)}else{T.addEventListener("load",g,false)}}(window,document,"script","tpwidget","//widget.seniverse.com/widget/chameleon.js"))</script>
<script>tpwidget("init", {
"flavor": "slim",
"location": "WX4FBXXFKE4F",
"geolocation": "enabled",
"language": "auto",
"unit": "c",
"theme": "chameleon",
"container": "tp-weather-widget",
"bubble": "enabled",
"alarmType": "badge",
"color": "#C6C6C6",
"uid": "自己申请",
"hash": "自己申请"
});
tpwidget("show");</script>
<!-- 知心结束-->
侧栏统计信息
首先在/usr/themes/handsome/functions.php
内添加以下代码
//在线人数
function online_users() {
$filename='online.txt'; //数据文件
$cookiename='Nanlon_OnLineCount'; //Cookie名称
$onlinetime=30; //在线有效时间
$online=file($filename);
$nowtime=$_SERVER['REQUEST_TIME'];
$nowonline=array();
foreach($online as $line){
$row=explode('|',$line);
$sesstime=trim($row[1]);
if(($nowtime - $sesstime)<=$onlinetime){
$nowonline[$row[0]]=$sesstime;
}
}
if(isset($_COOKIE[$cookiename])){
$uid=$_COOKIE[$cookiename];
}else{
$vid=0;
do{
$vid++;
$uid='U'.$vid;
}while(array_key_exists($uid,$nowonline));
setcookie($cookiename,$uid);
}
$nowonline[$uid]=$nowtime;
$total_online=count($nowonline);
if($fp=@fopen($filename,'w')){
if(flock($fp,LOCK_EX)){
rewind($fp);
foreach($nowonline as $fuid=>$ftime){
$fline=$fuid.'|'.$ftime."\n";
@fputs($fp,$fline);
}
flock($fp,LOCK_UN);
fclose($fp);
}
}
echo "$total_online";
}
//字数统计
function allOfCharacters() {
$chars = 0;
$db = Typecho_Db::get();
$select = $db ->select('text')->from('table.contents');
$rows = $db->fetchAll($select);
foreach ($rows as $row) { $chars += mb_strlen(trim($row['text']), 'UTF-8'); }
$unit = '';
if($chars >= 10000) { $chars /= 10000; $unit = '万'; }
else if($chars >= 1000) { $chars /= 1000; $unit = '千'; }
$out = sprintf('%.2lf %s',$chars, $unit);
return $out;
}
//总访问量
function theAllViews(){
$db = Typecho_Db::get();
$row = $db->fetchAll('SELECT SUM(VIEWS) FROM `typecho_contents`');
echo number_format($row[0]['SUM(VIEWS)']);
}
//响应时间
function timer_start() {
global $timestart;
$mtime = explode( ' ', microtime() );
$timestart = $mtime[1] + $mtime[0];
return true;
}
timer_start();
function timer_stop( $display = 0, $precision = 3 ) {
global $timestart, $timeend;
$mtime = explode( ' ', microtime() );
$timeend = $mtime[1] + $mtime[0];
$timetotal = number_format( $timeend - $timestart, $precision );
$r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
if ( $display ) {
echo $r;
}
return $r;
}
然后在/usr/themes/handsome/component/sidebar.php
内,博客信息位置替换为如下代码:
<?php if (@!in_array('info', Utils::checkArray($this->options->sidebarSetting))): ?>
<section id="blog_info" class="widget widget_categories wrapper-md clear">
<h5 class="widget-title m-t-none text-md"><?php _me("博客信息") ?></h5>
<ul class="list-group box-shadow-wrap-normal">
<?php Typecho_Widget::widget('Widget_Stat')->to($stat); ?>
<li class="list-group-item text-second"><span class="blog-info-icons"> <i data-feather="award"></i></span> <span
class="badge
pull-right"><?php $stat->publishedPostsNum() ?></span><?php _me("文章数目") ?></li>
<?php if (COMMENT_SYSTEM == 0): ?>
<li class="list-group-item text-second"> <span class="blog-info-icons"> <i data-feather="message-circle"></i></span>
<span class="badge
pull-right"><?php $stat->publishedCommentsNum() ?></span><?php _me("评论数目") ?></li>
<?php endif; ?>
<li class="list-group-item text-second"><span class="blog-info-icons"> <i data-feather="calendar"></i></span><span
class="badge
pull-right"><?php echo theAllViews();?></span><?php _me("受访次数") ?></li>
<li class="list-group-item text-second"><span class="blog-info-icons"> <i data-feather="edit"></i></span>
<span class="badge
pull-right"><?php echo allOfCharacters(); ?></span><?php _me("全站字数") ?></li>
<li class="list-group-item text-second"><span class="blog-info-icons"> <i data-feather="calendar"></i></span>
<span class="badge
pull-right"><?php echo Utils::getOpenDays(); ?></span><?php _me("运行天数") ?></li>
<li class="list-group-item text-second"><span class="blog-info-icons"> <i data-feather="activity"></i></span> <span
class="badge
pull-right"><?php echo Utils::getLatestTime($this); ?></span><?php _me("最后活动") ?></li>
</ul>
</section>
注:侧栏我没有引用在线人数和相应时间,如有需要自行在sidebar.php内按照相应格式引用。
标签显示数量
在sidebar.php
文件查找如下内容:
<?php Typecho_Widget::widget('Widget_Metas_Tag_Cloud','ignoreZeroCount=1&limit=30')->to($tags); ?>
修改30为自己想要显示的数量即可。
5 条评论
心知天气在屏幕宽度大于990px和小于1200px时会出现样式错乱 占位挤开了其他元素
心知天气会占位 在990px
没看到心知天气有地方申请uid和hash啊好像不填写也能用
免费版基本信息哪里,不填写我没尝试
那一天看到了 不过我就是去掉了uid和hash 然后正常使用没问题 建议你配置一个邮件提醒