Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Possible Duplicate:
append_content help

i have a code which is use to display twitter tweets but the problem is, it is displaying before the content of post, i know the problem is with echo, cause it is echoing first and then the post is coming, so the post comes after the tweets, when i tried to make the echoes to return then the tweets are not coming here is my code

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;
}
}
}
share|improve this question

marked as duplicate by Rarst, t31os, EAMann Dec 17 '10 at 14:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
no there is no error of duplicate entry –  ntechi Dec 17 '10 at 6:30

1 Answer 1

up vote 4 down vote accepted

Functions can only return one value. Change all the echo statements in your tweet function to concatenate a string, then return the string at the end of the function.

share|improve this answer
    
i tried that also, but then the tweets are not coming, see my original code, i changed it –  ntechi Dec 17 '10 at 6:29
1  
You are not concatenating a string, you are repeatedly overwriting it. Each time you assign a new string to $output you lose whatever you put in that variable before. Concatenation uses the . operator. –  Dan Grossman Dec 17 '10 at 6:38
    
hey its solved, thanks for your help –  ntechi Dec 17 '10 at 6:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.