Possible Duplicate:
append_content help
我有一个用来显示推特推文的代码,但问题是,它显示在帖子内容之前,我知道问题出在回声上,因为它先回声,然后帖子就来了,所以帖子就在推文之后,当我试图让回声返回推文时,推文就不来了这是我的代码
function append_the_content1($content) {
//if(get_option(\'tweetID\')!=null){
$content .= "<div class=\'post\'><p>".tweet(get_option(\'tweetID\'))."</p></div>";
return $content;
//}
//else{
//return $content;
//}
}
add_filter(\'the_content\', \'append_the_content1\');
function tweet(){
$doc = new DOMDocument();
if (get_option(\'tweetID\') != null) {
if($doc->load(\'http://twitter.com/statuses/user_timeline/\'.get_option(\'tweetID\').\'.rss\')) {
$output = "<ul>";
# number of <li> elements to display. 20 is the maximum
$max_tweets = 5;
$i = 1;
foreach ($doc->getElementsByTagName(\'item\') as $node) {
# fetch the title from the RSS feed.
# Note: \'pubDate\' and \'link\' are also useful (I use them in the sidebar of this blog)
$tweet = $node->getElementsByTagName(\'title\')->item(0)->nodeValue;
# the title of each tweet starts with "username: " which I want to remove
$tweet = substr($tweet, stripos($tweet, \':\') + 1);
# OPTIONAL: turn URLs into links
$tweet = preg_replace(\'@(https?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\.]*(\\?\\S+)?)?)?)@\',
\'<a href="$1">$1</a>\', $tweet);
# OPTIONAL: turn @replies into links
$tweet = preg_replace("/@([0-9a-zA-Z]+)/",
"<a href=\\"http://twitter.com/$1\\">@$1</a>",
$tweet);
$output = "Twiiter Updates:<li>". $tweet . "</li>\\n";
if($i++ >= $max_tweets) break;
}
$output = "</ul>\\n";
return $output;
}
}
}