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.

i have a function in my plugin append_the_content($content) this is used to display my function inside the post, but it is coming before the post, i want to make it after the post, for this i tried this code, but then too its not coming

function parse_twitter_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) {
  $feed = str_replace("&lt;", "<", $feed);
  $feed = str_replace("&gt;", ">", $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 fetch.

  /* 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 = "<b>".$username.": </b> "; // 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) {
    if(get_option('tweetID')!=null){
    $content .= "<div class='post'><p>".the_twitter_feed(get_option('tweetID'))."</p></div>";
       echo $content;
      }
       else{
       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>
<table>
<form method='post' action='options.php' style='margin:0 20px;'>
<?php wp_nonce_field('update-options'); ?>
<tr><td>Twitter UserID:</td><td><input type="text" name="tweetID"  value="<?php echo get_option('tweetID'); ?>" <?php echo get_option('tweetID'); ?> />
</td></tr>

<input type='hidden' name='action' value='update'/>
<input type='hidden' name='page_options' value='tweetID'/>

<tr><td><p class='submit'>
<input type='submit' name='Submit' value='Update Options &raquo;'/>
</p></td></tr>
</table>
</form>
<?php
}

how can i make it after the post???

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Edited, try this

<?php

function parse_twitter_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) {
    $feed = str_replace("&lt;", "<", $feed);
    $feed = str_replace("&gt;", ">", $feed);
    $clean = explode("<content type=\"html\">", $feed);

    $amount = count($clean) - 1;

    $output = $prefix;

    for ($i = 1; $i <= $amount; $i++) {
        $cleaner = explode("</content>", $clean[$i]);
        $output .= $tweetprefix;
        $output .= $cleaner[0];
        $output .= $tweetsuffix;
    }

    $output .= $suffix;

    return $output;
}

function the_twitter_feed($username) {
    // $username = "Mba_"; // Your twitter username.
    $limit = "5"; // Number of tweets to fetch.

    /* 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 = "<b>" . $username . ": </b> "; // 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)
        return parse_twitter_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix);
}

function append_the_content($content) {
    if (get_option('tweetID') != null) {
        $content .= "<div class='post'><p>" . the_twitter_feed(get_option('tweetID')) .
            "</p></div>";
        return $content;
    } else {
        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>
<table>
<form method='post' action='options.php' style='margin:0 20px;'>
<?php

    wp_nonce_field('update-options');

?>
<tr><td>Twitter UserID:</td><td><input type="text" name="tweetID"  value="<?php

    echo get_option('tweetID');

?>" <?php

    echo get_option('tweetID');

?> />
</td></tr>

<input type='hidden' name='action' value='update'/>
<input type='hidden' name='page_options' value='tweetID'/>

<tr><td><p class='submit'>
<input type='submit' name='Submit' value='Update Options &raquo;'/>
</p></td></tr>
</table>
</form>
<?php

}

?>
share|improve this answer
    
no still not working, still the content is coming after the tweets –  ntechi Dec 14 '10 at 13:10
    
edited.. try now –  Atif Mohammed Ameenuddin Dec 15 '10 at 6:52
    
hey now i tried the code but the problem is now i am getting the div box after my content, but the tweets are not coming now y is it so? also if i try to get the tweets manually with the help of function, then also i am not getting them –  ntechi Dec 15 '10 at 8:08
1  
edited.. that should be it –  Atif Mohammed Ameenuddin Dec 15 '10 at 8:49
    
hey it worked, thanks a lot for your help can you just xplain me, what you did? –  ntechi Dec 15 '10 at 8:54
show 2 more comments

Most likely your the_twitter_feed() function echoes results instead of returning them.

share|improve this answer
    
so how can i bring it after the post? –  ntechi Dec 14 '10 at 6:21
1  
Adjusting the function to return(or support both return/echo), or writing a new one that returns instead of echoing it's result.. –  t31os Dec 14 '10 at 9:44
    
so in that case what i have to do? plz just tell what changes i have to make? –  ntechi Dec 14 '10 at 10:16
    
Having tracked down your function: wordpress.stackexchange.com/questions/5181/… ... i'd say you need to trace where parse_feed is defined(it's not a WordPress function) and find an alternative that can return the data. –  t31os Dec 14 '10 at 11:12
    
sorry to say this but still i am not getting you, i just started php, just tell where code is to be changed sorry to ask this question, but can you tell me where i need to change the code? –  ntechi Dec 14 '10 at 11:25
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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