<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>陈志伟博客 &#187; 挂件</title>
	<atom:link href="http://chenzhiwei.net/tag/%e6%8c%82%e4%bb%b6/feed/" rel="self" type="application/rss+xml" />
	<link>http://chenzhiwei.net</link>
	<description>善始者实繁，克终者盖寡。</description>
	<lastBuildDate>Sat, 17 Mar 2012 04:16:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>博客上添加twitter挂件的方法-超级简单</title>
		<link>http://chenzhiwei.net/2010/06/add-twitter-gadget-on-your-blog/</link>
		<comments>http://chenzhiwei.net/2010/06/add-twitter-gadget-on-your-blog/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 12:23:03 +0000</pubDate>
		<dc:creator>zhiwei</dc:creator>
				<category><![CDATA[互联网络]]></category>
		<category><![CDATA[建站相关]]></category>
		<category><![CDATA[gadget]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[挂件]]></category>

		<guid isPermaLink="false">http://chenzhiwei.net/?p=30219</guid>
		<description><![CDATA[最近一不小心发现原来在博客上添加twitter挂件很简单。只需要一个twitter api  地址，几行代码就可以了，现在贴出来与各位同学分享。以下是相关说明。 假设你的twitter api地址是：http://abc.com/api/ 只需要将以下代码第六行中的twitter_username改为你自己的twitter用户名，其中的count=2是说明只显示最新的两条推。你可以根据自己的需求而适当更改。将这几行代码加到&#60;head&#62;&#60;/head&#62;之间，当然，你也可以加到主题的function.php或其他.php文件里面。看完以下代码后你会发现，只需稍做修改就可以运用到静态网页中了。 1 2 3 4 5 6 7 8 9 &#60;?php function twitter_show&#40;&#41; &#123; ?&#62; &#60;script type=&#34;text/javascript&#34; src=&#34;http://abc.com/api/javascripts/blogger.js&#34;&#62;&#60;/script&#62; &#60;script type=&#34;text/javascript&#34; src=&#34;http://abc.com/api/statuses/user_timeline/twitter_username.json?callback=twitterCallback2&#38;count=2&#34;&#62;&#60;/script&#62; &#60;?php &#125; ?&#62; 以下代码是显示twitter条目的代码，你可以加到博客侧边栏或者加到博客顶部，像我博客(chenzhiwei.net)这样，由于博客主机速度原因，加载javascript太慢，所以将顶部tweets去掉了，效果见http://chenzhiwei.net/twitter/tweets.php ，因api原因，有时可能会显示不出来，刷新一下就OK了。如果懂CSS的话，你自己还可以优化一下tweets的显示，使用其更加美观。 1 2 3 4 5 6 &#60;div id=&#34;&#34;&#62; &#60;ul id=&#34;twitter_update_list&#34;&#62; &#60;li&#62;&#38;nbsp;loading...&#60;/li&#62; &#60;?php twitter_show&#40;&#41;; ?&#62; &#60;/ul&#62; &#60;/div&#62; 到此，博客上添加twitter挂件功能就实现了，非常简单。 下面给出一个测试例子：index.php文件，将该文件中的http://abc.com/api/改为你自己的twitter api地址，然后运行该文件后就会显示两条tweets。效果见http://chenzhiwei.net/twitter/tweets.php 。 1 2 3 4 [...]]]></description>
			<content:encoded><![CDATA[<p>最近一不小心发现原来在博客上添加twitter挂件很简单。只需要一个twitter api  地址，几行代码就可以了，现在贴出来与各位同学分享。以下是相关说明。</p>
<p>假设你的twitter api地址是：http://abc.com/api/</p>
<p>只需要将以下代码第六行中的<span style="color: #ff0000;">twitter_username</span>改为你自己的twitter用户名，其中的<span style="color: #ff0000;">count=2</span>是说明只显示最新的两条推。你可以根据自己的需求而适当更改。将这几行代码加到&lt;head&gt;&lt;/head&gt;之间，当然，你也可以加到主题的function.php或其他.php文件里面。看完以下代码后你会发现，只需稍做修改就可以运用到静态网页中了。<span id="more-30219"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> twitter_show<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;script type=&quot;text/javascript&quot; src=&quot;http://abc.com/api/javascripts/blogger.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;http://abc.com/api/statuses/user_timeline/twitter_username.json?callback=twitterCallback2&amp;count=2&quot;&gt;&lt;/script&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>以下代码是显示twitter条目的代码，你可以加到博客侧边栏或者加到博客顶部，像我<a href="http://chenzhiwei.net">博客</a>(<a href="http://chenzhiwei.net">chenzhiwei.net</a>)这样，由于博客主机速度原因，加载javascript太慢，所以将顶部tweets去掉了，效果见<a href="http://chenzhiwei.net/twitter/tweets.php" target="_blank">http://chenzhiwei.net/twitter/tweets.php</a> ，因api原因，有时可能会显示不出来，刷新一下就OK了。如果懂CSS的话，你自己还可以优化一下tweets的显示，使用其更加美观。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #00AA00;">&gt;</span>
	&lt;ul id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;twitter_update_list&quot;</span><span style="color: #00AA00;">&gt;</span>
		&lt;li<span style="color: #00AA00;">&gt;</span>&amp;nbsp<span style="color: #00AA00;">;</span>loading...&lt;/li<span style="color: #00AA00;">&gt;</span>
		&lt;?php twitter_show<span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> ?<span style="color: #00AA00;">&gt;</span>
	&lt;/ul<span style="color: #00AA00;">&gt;</span>
&lt;/div<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>到此，博客上添加twitter挂件功能就实现了，非常简单。<br />
下面给出一个测试例子：index.php文件，将该文件中的http://abc.com/api/改为你自己的twitter api地址，然后运行该文件后就会显示两条tweets。效果见<a href="http://chenzhiwei.net/twitter/tweets.php" target="_blank">http://chenzhiwei.net/twitter/tweets.php</a> 。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head profile=&quot;http://gmpg.org/xfn/11&quot;&gt;
&lt;title&gt;show tweets&lt;/title&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> twitter_show<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;script type=&quot;text/javascript&quot; src=&quot;http://abc.com/api/javascripts/blogger.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;http://abc.com/api/statuses/user_timeline/chenzhiwei.json?callback=twitterCallback2&amp;count=2&quot;&gt;&lt;/script&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/head&gt;
&lt;body&gt;
    &lt;ul id=&quot;twitter_update_list&quot;&gt;
        &lt;li&gt;&amp;nbsp;&lt;/li&gt;
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> twitter_show<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p style="font-weight: bold;">&copy; 2010, <a href="http://chenzhiwei.net">chenzhiwei.net</a>. 版权所有.  <br />本文永久链接：<a title="博客上添加twitter挂件的方法-超级简单" href="http://chenzhiwei.net/2010/06/add-twitter-gadget-on-your-blog/">http://chenzhiwei.net/2010/06/add-twitter-gadget-on-your-blog/</a></p><hr /><div  class="related_post_title">相关日志</div><ul class="related_post"><li><a href="http://chenzhiwei.net/2009/08/the-new-discovery/" title="我这几天的新发现">我这几天的新发现</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://chenzhiwei.net/2010/06/add-twitter-gadget-on-your-blog/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

