Support » Plugins » Twitter Shortcode intergration

  • Hi, Im trying to integrate my twitter function into wordpress via a shortcode, now everything works fine except it’s not allowing me to set a number of tweets to display and is only allowing the 1 tweet to be displayed.

    Here’s the twitter function im using to pull the tweets;

    class Twitter
      public $tweets = array();
      public function __construct($user, $limit = 5)
        $user = str_replace(' OR ', '%20OR%20', $user);
        $feed = curl_init(''. $user .'&rpp='. $limit);
        curl_setopt($feed, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($feed, CURLOPT_HEADER, 0);
        $xml = curl_exec($feed);
        $result = new SimpleXMLElement($xml);
        foreach($result->entry as $entry)
            $tweet = new stdClass();
            $tweet->id = (string) $entry->id;
            $user = explode(' ', $entry->author->name);
            $tweet->user = (string) $user[0];
            $tweet->author = (string) substr($entry->author->name, strlen($user[0])+2, -1);
            $tweet->title = (string) $entry->title;
            $tweet->content = (string) $entry->content;
            $tweet->updated = (int) strtotime($entry->updated);
            $tweet->permalink = (string) $entry->link[0]->attributes()->href;
            $tweet->avatar = (string) $entry->link[1]->attributes()->href;
            array_push($this->tweets, $tweet);
        unset($feed, $xml, $result, $tweet);
      public function getTweets() { return $this->tweets; }

    Here’s the shortcode im using

    function twitter_feed($atts, $content = null) {
    		"user"  => '',
    		"limit"  => ''
    	), $atts));
    	 $feed = new Twitter($user , $limit);
    $tweets = $feed->getTweets();
    foreach ($tweets as $tweet) {
    return '<ul><li>'. $tweet->content .' by <a href="'. $tweet->user .'">'. $tweet->author .'</a></li></ul>';
    add_shortcode("twitter", "twitter_feed");

    Example Shortcode
    [twitter user="YourTwitterUserName" limit="5"]

    As I said above this code works fine apart from the tweet limit it, only ever pulls 1 tweet.

    Now I’ve tried putting the code directly into the theme to see if it was a problem with the function but it works fine, so I must be doing something wrong in the shortcode. Any idea’s folks?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I would try using the shortcode:
    [twitter user=”YourTwitterUserName”, limit=”5″]

    If that doesn’t work then no idea, it looks fine. I’m only suggesting that as a solution because you’ve said the shortcod ei would have used doesn’t work.

    Thanks for the reply, it still doesn’t work though.

    hopefully someone will have a solution sooner or later.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Twitter Shortcode intergration’ is closed to new replies.