【发布时间】:2012-03-21 12:57:01
【问题描述】:
我已经尝试了大约 15 种不同的代码变体,但都无济于事。基本上,我在我的 Wordpress 网站上想要的只是我最新的推文。下面的代码来自 Smashing Magazine,显然在我的代码中我已将 $username 更改为我的 Twitter 用户名。到目前为止没有任何效果,我不知道它是什么。它正在连接到 Twitter,因为当代码存在时加载页面需要更长的时间。我还尝试了一个,它向我展示了我有多少关注者并显示了我的用户名,但没有显示我的推文。如果有帮助的话,这是我的网站...
http://newmedia.leeds.ac.uk/ug10/cs10cwh/wordpress/
为了加快加载时间,我已经删除了这一分钟的代码。任何帮助将不胜感激。
<?php
// Your twitter username.
$username = "TwitterUsername";
// Prefix - some text you want displayed before your latest tweet.
// (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
$prefix = "<h2>My last Tweet</h2>";
// Suffix - some text you want display after your latest tweet. (Same rules as the prefix.)
$suffix = "";
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";
function parse_feed($feed) {
$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
return $tweet;
}
$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>
【问题讨论】:
-
如果您在
file_get_contents调用之后进行var_dump($twitterFeed),是否有数据?
标签: php html wordpress twitter