Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7939931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:14:24+00:00 2026-06-03T23:14:24+00:00

I’m wondering why, within the sidebar of my wordpress theme, This code is not

  • 0

I’m wondering why, within the sidebar of my wordpress theme, This code is not pulling in my latest tweets?

<?php
/*
    PHP Twitter Feed Importer
       @mradamdavies
     www.elevatelocal.co.uk
==-----------------------------*/

class pull_tweets { // Create a basic class

var $twitter_handle;    // Twitter username
var $tweet_limit;       // Max tweets to return
var $tweet_links;       // Show @profile links
var $tweet_tags;        // Show #tag links
var $tweet_avatar;      // Show twitter avatar
var $tweet_profile;     // Show twitter profile link

var $hard_max;          // Real max tweets (Used to filter out @replies)
var $i;                 // Tweet counter

function show_tweet_links($tweet_links_output, $tweet_links) { // Find and replace @replies with links
        if($tweet_links == true) {
            $find  = '/\@([a-zA-Z]+)/';
            $replace  = '<a class="hash_link" href="http://twitter.com/'.strtolower('\1').'" rel="nofollow">@\1</a>';
            $tweet_links_text = preg_replace($find,$replace,$tweet_links_output);
            return $tweet_links_text;
        }
        else { return $tweet_links_output; }
}

function show_hash_tags($tweet_hashtags_output, $tweet_tags) { // Find and replace #tags with links
    if($tweet_tags == true) {
        $find_hash_tag  = '/\#([a-zA-Z]+)/';
        $replace_hash_tag  = '<a class="hash_link" href="http://twitter.com/search?q=%23'.strtolower('\1').'" rel="nofollow">#\1</a>';
        return
        preg_replace($find_hash_tag,$replace_hash_tag,$tweet_hashtags_output);
    }
    else { return $tweet_hashtags_output; }
}

function show_twitter_avatar($tweet_avatar_output, $tweet_avatar) { // Show avatar
    if($tweet_avatar == true) {
        return '<img src="'.$tweet_avatar_output.'" alt="" />';
    }
    else { return false; }
}

function show_twitter_profile_link($tweet_profile_output, $tweet_profile) { // Insert profile link
    if($tweet_profile == true) {
        return '<a class="profile_link" href="http://twitter.com/'.$tweet_profile_output.'">@'.$tweet_profile_output.'</a>';
    }
    else { return false; }
}

// Create a basic function to pull latest tweets
function tweets($twitter_handle, $tweet_limit, $tweet_links, $tweet_tags, $tweet_avatar, $tweet_profile) {

        /* Store Tweets in a JSON object */
        $tweet_feed =   json_decode(file_get_contents('http://api.twitter.com/1/statuses/user_timeline.json?screen_name='.
                        $twitter_handle.'&exclude_replies=false&count='.$hard_max));

        $i = 0; // Start the tweet limit counter
        foreach ($tweet_feed as $tweet) { // Loop through the tweets

            if ($tweet->in_reply_to_user_id == '' && $i != $tweet_limit) { // Don't show direct @replies
                ++$i; // Increase tweet counter

    // Check true/false flags and return output accoringly
    $tweet_text = $tweet->text;
    $tweet_text = pull_tweets::show_tweet_links($tweet_text,$tweet_links); // Show @reply links?
    $tweet_text = pull_tweets::show_hash_tags($tweet_text,$tweet_tags); // Show #tag links?
    $twitter_avatar =
pull_tweets::show_twitter_avatar($tweet->user->profile_image_url,$tweet_avatar); // Show avatar?
    $twitter_profile =
    pull_tweets::show_twitter_profile_link($twitter_handle,$tweet_profile); // Show main profile link?

    // Echo our tweet contents
    echo '
    <div class="tweet_bg">',$twitter_avatar,'
    <p>'.$tweet_text.'<br />'.$twitter_profile.'</p>
    </div>';

            }

        } // end of foreach

    } // end of tweets function

} // end of pull_tweets class
?>


<script language="javascript">
$my_tweets = new pull_tweets();

echo $my_tweets->tweets('mradamdavies', 5, true, true, true, true);
</script>

Referred by this tutorial:
*http://www.elevatelocal.co.uk/blog/php-twitter-feed-importer-05094504*

I want to do this with PHP or minimal JavaScript. Currently Twitter Widgets are not working on my site for some reason.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:14:25+00:00Added an answer on June 3, 2026 at 11:14 pm

    The PHP in your <script> isn’t getting parsed as PHP. You likely want

    <?php
    $my_tweets = new pull_tweets();
    
    $my_tweets->tweets('mradamdavies', 5, true, true, true, true);
    ?>
    

    As Jamie pointed out, the HTML produced by tweets() isn’t JavaScript, so you don’t need the <script> tag at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.