参考了万戈的两篇文章,还有N次google,终于把底部的公告栏做的有了点意思。
做这个的准备工作还是很多的。需要一个微博(这个简单,程序上传安装就搞定,直接用其他的微博也行),一个可以缩短网址的网站API(这个不是必须的,需要缩短网址就要,不需要就不用)。
直接上方法吧。
第一步:在functions.php中添加下面代码,注意修改需要的嘀咕的账号密码和缩短网址的API。
1: function update_digu($status){
2: require_once(ABSPATH.WPINC.'/class-snoopy.php');
3: $snoop = new Snoopy;
4: $snoop->user = '帐号';
5: $snoop->pass = '密码';
6: $snoop->submit('http://api.minicloud.com.cn/statuses/update.json', array('content' => urlencode($status),'source' => 'wpthread'));
7: }
8: add_action('publish_post', 'publish_post_2_digu', 0);
9: function publish_post_2_digu($post_ID){
10: $digu = get_post_meta($post_ID, 'digu', true);
11: if($digu) return;
12: $shortlink = 'http://uway.me/api.php?url=' . get_permalink($post_ID);
13: $url_contents = file_get_contents($shortlink);
14: $status = $_POST['post_title'].' '.$url_contents;
15: update_digu($status);
16: add_post_meta($post_ID, 'digu', 'true', true);
17: }
第二步:添加下面代码到footer.php或者herader.php的/body标签前面,同样注意修改我的个人信息。
1: <div id="wgToolBar">
2: <?php
3: function wgToolBar_notice( $num = 5){
4: date_default_timezone_set('PRC');
5: require_once (ABSPATH . WPINC . '/class-feed.php');
6: $feed = new SimplePie();
7: $feed->set_feed_url( 'http://t.iceray.net/rss.xml' ); //RSS 地址
8: $feed->set_file_class('WP_SimplePie_File');
9: $feed->set_cache_duration( 600 ); //缓存时间,600秒
10: $feed->init();
11: $feed->handle_content_type();
12: $items = $feed->get_items( 0, $num );
13: echo '<ul id="wgNotice">';
14: foreach ($items as $item) {
15: echo '<li><a title="'.strip_tags($item->get_date('j F Y | g:i a')).'" href="'.$item->get_permalink().'">'.strip_tags($item->get_content()).'</a></li>';
16: }
17: echo '</ul>';
18: }
19: wgToolBar_notice( 5 ); //输出数量
20: ?>
21: <script type="text/javascript" src="http://t.iceray.net/badge.php"></script>
22: <ul id="wgSNS">
23: <li><a id="tb_tencent" href="http://t.qq.com/iceray" target="_blank" title="QQ 微博">QQ 微博</a></li>
24: <li><a id="tb_digu" href="http://digu.com/iceray" target="_blank" title="嘀咕">嘀咕</a></li>
25: <li><a id="tb_facebook" href="http://www.facebook.com/wange1228" target="_blank" title="Facebook">Facebook</a></li>
26: <li><a id="tb_fav" title="加入收藏" href="javascript:void(0)" onclick="addFavorite()">加入收藏</a></li>
27: <li><a id="tb_mail" title="Email" href="mailto:i@iceray.net">Email</a></li>
28: <li><a id="tb_rss" title="订阅本站" target="_blank" href="http://feed.iceray.net">订阅本站</a></li>
29: </ul>
30: <!-- End 万戈牌工具条代码版 -->
31: <script type="text/javascript">
32: jQuery(document).ready(function($){
33: $('#wgNotice').css('width',$(window).width() - $('#wgSNS').outerWidth() -40);
34: $("#wgNotice li:gt(0)").css("display","none");var B=$("#wgNotice li:last");var C=$("#wgNotice li:first");setInterval(function(){if(B.is(":visible")){C.fadeIn(500).addClass("in");B.hide()}else{$("#wgNotice li:visible").addClass("in");$("#wgNotice li.in").next().fadeIn(500);$("#wgNotice li.in").hide().removeClass("in")}},5000);
35: });
36: function addFavorite(){if(document.all){try{window.external.addFavorite(window.location.href,document.title)}catch(e){alert("加入收藏失败,请使用 Ctrl+D 进行添加")}}else if(window.sidebar){window.sidebar.addPanel(document.title,window.location.href,"")}else{alert("加入收藏失败,请使用 Ctrl+D 进行添加")}}
37: </script>
这段代码,如果已经加载JQ库,就直接修改复制;没有加载JQ库请在第三十一行前添加
1: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=1.3.2"></script>
切记,如果多加载会造成其他JS代码混乱。
第三步:添加下面样式到style.css。
1: /* Start 公有样式 */
2: html{_background-image:url(about:blank);_background-attachment:fixed;}
3: #wgToolBar{width:100%;height:30px;position:fixed;background:#000;z-index:9999;overflow:hidden;opacity:0.7;filter:alpha(opacity=70);-moz-opacity:.7;}
4: #wgToolBar a{text-decoration:none;}
5: #wgNotice{float:left;background:url(images/notice_icon.gif) no-repeat 10px 3px;margin:0;padding:0 0 0 40px;}
6: #wgNotice li{list-style-type:none;color:#fff;font:13px/30px Arial,SimSun;}
7: #wgNotice li a{color:#fff;}
8: #wgNotice li a:hover{color:#06c;}
9: #wgSNS{float:right;padding:5px 10px 0 0;margin:0;}
10: #wgSNS li{float:left;margin:0 5px;display:inline;list-style-type:none;}
11: #wgSNS li a{width:20px;height:20px;display:block;background:url(images/sns_icon.png) no-repeat;text-indent:-9999em;}
12: #wgSNS li a:hover{transform:scale(1.5);-webkit-transform:scale(1.5);-moz-transform:scale(1.5);-o-transform:scale(1.5);}
13: #wgSNS #tb_fav{background-position:0 0;}
14: #wgSNS #tb_mail{background-position:0 -25px;}
15: #wgSNS #tb_rss{background-position:0 -50px;}
16: #wgSNS #tb_sohu{background-position:0 -75px;}
17: #wgSNS #tb_twitter{background-position:0 -100px;}
18: #wgSNS #tb_sina{background-position:0 -125px;}
19: #wgSNS #tb_net163{background-position:0 -150px;}
20: #wgSNS #tb_baidu{background-position:0 -175px;}
21: #wgSNS #tb_douban{background-position:0 -200px;}
22: #wgSNS #tb_facebook{background-position:0 -225px;}
23: #wgSNS #tb_tencent{background-position:0 -250px;}
24: #wgSNS #tb_digu{background-position:0 -275px;}
25: /* End 公有样式 */
26: /* Start 顶部工具条 */
27: body{margin-top:30px;}
28: #wgToolBar{border-radius:0 0 5px 5px;box-shadow:0px 5px 5px #565656;-moz-border-radius:0 0 5px 5px;-webkit-border-radius:0 0 5px 5px;-khtml-border-radius:0 0 5px 5px;-webkit-box-shadow:0px 5px 5px #565656;-moz-box-shadow:0px 5px 5px #565656;top:0;_position:absolute;_top:expression(0+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+"px");}
29: /* End 顶部工具条 */
30: /* Start 底部工具条 */
31: body{margin-bottom:30px;}
32: #wgToolBar{border-radius:5px 5px 0 0;box-shadow:0px -5px 5px #565656;-moz-border-radius:5px 5px 0 0;-webkit-border-radius:5px 5px 0 0;-khtml-border-radius:5px 5px 0 0;-webkit-box-shadow:0px -5px 5px #565656;-moz-box-shadow:0px -5px 5px #565656;bottom:0;_position:absolute;_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,0)||0)-(parseInt(this.currentStyle.marginBottom,0)||0)));}
33: /* End 底部工具条 */
这个样式,你需要顶部的就删掉底部,需要底部就删掉顶部,不能同时用。
这些代码是万戈大哥写的,我只是在此基础上进行了实验,不懂的可以据此参考。
( ˇˍˇ )还有点不完美的地方,调用微博不能做到实时性,具体延迟多少还没注意,完了在整整,能解决的话就更新到这吧。
PS:参照此篇,可以实时调用微博了。%>_<%又出现一个新问题,用WLW发表文章产生的文章地址发送到嘀咕,发言没有文章名称是怎么回事捏,盼盼盼有童鞋告知。
感谢您的文章~! :kucing_naksir:
客气客气 :foryourinfo:
发现大家都在整这个玩意,貌似也有那么点意思哦
比主题自带的公告方便不少
弄上实时更新吧···真的很给力······
多亏你的那段代码了。
实时更新很爽
上个主题用过万戈工具条 也是代码的 一会就试试新主题能否用上
你的主题颜色很淡,要改改CSS
这个方式不好之处是有些functions.php是加密的,因为是收费主题,所以无法修改functions.php,导致无法使用。
见多了加密的JS,倒是没见加密的functions.php
我也是第一次见到,哎。
如果是买的主题可以找作者要源文件改丫