我試過了大約15個不同的代碼變化,試圖讓這個工作無濟於事。基本上我想在我的Wordpress網站上是我最新的推文。下面的代碼來自Smashing雜誌,顯然在我的代碼中,我已將$ username更改爲我的Twitter用戶名。目前爲止沒有任何工作,而且我對此感到不知所措。它連接到Twitter,因爲代碼存在時加載頁面需要更長的時間。我也嘗試了一個向我展示了多少追隨者,並顯示了我的用戶名但未顯示我的推文。這是我的網站,如果它有助於在所有...在WordPress的網站上最新的鳴叫 - 沒有顯示
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)',是否有數據? – 2012-03-03 03:43:06
是的,它說bool(false)。 – GuerillaRadio 2012-03-03 03:47:14