这段代码对我来说非常好用,但我只是想知道,我怎么能在发完帖子后把它带来,目前我所有的推特都在帖子之前,我怎么能在帖子之前发布呢??
function parse_twitter_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) {
$feed = str_replace("<", "<", $feed);
$feed = str_replace(">", ">", $feed);
$clean = explode("<content type=\\"html\\">", $feed);
$amount = count($clean) - 1;
echo $prefix;
for ($i = 1; $i <= $amount; $i++) {
$cleaner = explode("</content>", $clean[$i]);
echo $tweetprefix;
echo $cleaner[0];
echo $tweetsuffix;
}
echo $suffix;
}
function the_twitter_feed($username) {
// $username = "Mba_"; // Your twitter username.
$limit = "5"; // Number of tweets to pull in.
/* These prefixes and suffixes will display before and after the entire block of tweets. */
$prefix = ""; // Prefix - some text you want displayed before all your tweets.
$suffix = ""; // Suffix - some text you want displayed after all your tweets.
$tweetprefix = ""; // Tweet Prefix - some text you want displayed before each tweet.
$tweetsuffix = "<br>"; // Tweet Suffix - some text you want displayed after each tweet.
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $limit;
$twitterFeed = get_transient($feed);
if (!$twitterFeed) {
$twitterFeed = wp_remote_fopen($feed);
set_transient($feed, $twitterFeed, 3600); // cache for an hour
}
if ($twitterFeed)
parse_twitter_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix);
}
function append_the_content($content) {
$content .= the_twitter_feed(get_option(\'tweetID\'));
return $content;
}
add_filter(\'the_content\', \'append_the_content\');
add_action(\'admin_menu\',\'tweet_fetch\');
function tweet_fetch(){
add_options_page(\'Tweet\',\'Tweet\', 8, \'tweet\', \'tweet_fetcher\');
}
function tweet_fetcher(){
?>
<h2>Tweet Fetcher options</h2>
<form method=\'post\' action=\'options.php\' style=\'margin:0 20px;\'>
<?php wp_nonce_field(\'update-options\'); ?>
<p>Twitter UserID:<input type="text" name="tweetID" value="<?php echo get_option(\'tweetID\'); ?>" <?php echo get_option(\'tweetID\'); ?> />
</p>
<input type=\'hidden\' name=\'action\' value=\'update\'/>
<input type=\'hidden\' name=\'page_options\' value=\'tweetID\'/>
<p class=\'submit\'>
<input type=\'submit\' name=\'Submit\' value=\'Update Options »\'/>
</p>
</form>
<?php
}
最合适的回答,由SO网友:Patriek 整理而成
我不完全确定您想要什么,但我注意到,对于position,echo并不总是给出正确的位置,尝试构建一个大字符串,然后回显完整的结果,或者只是返回结果。
像这样:
$输出=echo$前缀$输出。=echo$tweetprefix$输出。=echo$cleaner[0]$输出。=echo$tweetsuffix$输出。=echo$后缀;
返回$输出
如果要使用echo,请使用逗号分隔字符串,如下所示:
echo$string1、$string2、$string3等。