Typecho CSS3個性留言板讀者墻頁面的添加方法
看到文章的首圖相信大家都不陌生,可能其他博客的讀者墻或者留言薄頁面都見過,挺簡約的真實記錄博客的訪客,留下的足跡,便於回訪,這也算是博客裏面互動的一個重要依據或者途徑,下面就來說說在Typecho下該如何實現這麼個性的訪問記錄:
首先、把下面代碼粘貼到當前主題的functions.php頁面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | //獲得讀者墻 function getFriendWall() { $db = Typecho_Db::get(); $sql = $db->select('COUNT(author) AS cnt', 'author', 'url', 'mail') ->from('table.comments') ->where('status = ?', 'approved') ->where('type = ?', 'comment') ->where('authorId = ?', '0') ->where('mail != ?', 'admin@ben-lab.com') //排除自己上墻 ->group('author') ->order('cnt', Typecho_Db::SORT_DESC) ->limit('15'); //讀取幾位用戶的信息 $result = $db->fetchAll($sql); if (count($result) > 0) { $maxNum = $result[0]['cnt']; foreach ($result as $value) { $mostactive .= '<li><a target="_blank" rel="nofollow" href="' . $value['url'] . '"><span class="pic" style="background: url(http://1.gravatar.com/avatar/'.md5(strtolower($value['mail'])).'?s=36&d=&r=G) no-repeat; "></span><em>' . $value['author'] . '</em><strong>+' . $value['cnt'] . '</strong><br />' . $value['url'] . '</a></li>'; } echo $mostactive; } } |
其次、在主題目錄裏新建一個guestbook.php,粘貼以下代碼,當然,新建頁面的名稱可以自己填寫,本篇是以guestbook為例,你懂的
1 2 3 4 5 6 7 | <?php /** * 自定義頁面模板 * * @package custom */ ?> |
第三、打開當前主題的page.php,復制全部代碼.然後粘貼到guestbook.php,接著其次那步下面的代碼
第四、替換代碼,搜索下面代碼替換成再下面內容
1 | php<?php $this->content(''); ?> |
替換成
1 2 3 4 | <div id="list-post"> <ul class='readers-list'> <?php getFriendWall(); ?> </ul></div> |
第五、打開主題的style.css,粘貼以下代碼
1 2 3 4 5 6 7 8 9 10 11 12 | .readers-list {line-height:16px;text-align:left;_zoom:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;-o-text-} .readers-list li{width:180px;float:left;*margin-right:-1px;list-style:none;} .readers-list a,.readers-list a:hover strong{background-color:#f2f2f2;background-image:-webkit-linear-gradient(#f8f8f8,#f2f2f2);background-image:-moz-linear-gradient(#f8f8f8,#f2f2f2);background-image:linear-gradient(#f8f8f8,#f2f2f2);} .readers-list a{position:relative;display:block;height:30px;margin:4px;padding:2px 4px 2px 44px;color:#999;overflow:hidden;border:#ccc 1px solid;border-radius:2px;box-shadow:#eee 0 0 2px;font-size:10px;line-height:14px;} .readers-list .pic,.readers-list em,.readers-list strong{-webkit-transition:all .2s ease-out;-moz-transition:all .2s ease-out;transition:all .2s ease-out;} .readers-list .pic{width:30px;height:30px;float:left;margin:0 8px 0 -40px;border-radius:2px;} .readers-list em{color:#666;font-style:normal;margin-right:10px;font:bold 12px/16px microsoft yahei;} .readers-list strong{color:#ddd;width:34px;text-align:right;position:absolute;right:6px;top:4px;font:bold 14px/16px microsoft yahei;} .readers-list a:hover{border-color:#bbb;box-shadow:#ccc 0 0 2px;background-color:#fff;background-image:none;} .readers-list a:hover .pic{opacity:.6;margin-left:0;} .readers-list a:hover em{color:#EE8B17;font:bold 12px/36px microsoft yahei;} .readers-list a:hover strong{color:#EE8B17;right:134px;top:0;text-align:center;border-right:#ccc 1px solid;height:34px;line-height:34px;} |
第六、新建頁面或者編輯你的讀者墻頁面,點擊底部高級選項,在自定義模版選擇"自定義頁面模版"發布即可!
好东西 谢谢分享先收藏一下下 嘻嘻