cahamilton Posted May 24, 2009 Share Posted May 24, 2009 Hey guys. I've been working on a script recently, which Im going to be using to take my recent "Tweets" from Twitter, and post them into my portfolio site. So far, all is good and I've been able to retrieve this data using the API feeds. The only problem is, I cant find anywhere in the API that allows me to control how many entries will show up on my page. Is there any way using PHP, to restrict how many entries are fed out? Here's the code I've been working with so far.... <?php $user_id = "USER_ID"; $feed_url = "http://twitter.com/statuses/user_timeline/".$user_id.".rss"; $sxml_twitter = @simplexml_load_file($feed_url); ?> <?php foreach ($sxml_twitter->channel->item as $entry) { $news_title = $entry->description; $date = $entry->pubDate; ?> <?php echo " <ul> <li class='tweet'>$news_title</li> <li class='date_twitter'>$date</li> </ul>"; ?> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159424-solved-number-of-twitter-posts/ Share on other sites More sharing options...
RussellReal Posted May 24, 2009 Share Posted May 24, 2009 set a variable, like $loop; set it to 0 $loop = 0; foreach (.....) { $loop++; if ($loop == 10) break; } Quote Link to comment https://forums.phpfreaks.com/topic/159424-solved-number-of-twitter-posts/#findComment-840963 Share on other sites More sharing options...
hitman6003 Posted May 24, 2009 Share Posted May 24, 2009 Use a for loop... <?php for ($i = 0; $i < 10; $i ++) { $entry = $sxml_twitter->channel->item[$i]; $news_title = $entry->description; $date = $entry->pubDate; echo " <ul> <li class='tweet'>$news_title</li> <li class='date_twitter'>$date</li> </ul>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159424-solved-number-of-twitter-posts/#findComment-840966 Share on other sites More sharing options...
cahamilton Posted May 24, 2009 Author Share Posted May 24, 2009 Use a for loop... <?php for ($i = 0; $i < 10; $i ++) { $entry = $sxml_twitter->channel->item[$i]; $news_title = $entry->description; $date = $entry->pubDate; echo " <ul> <li class='tweet'>$news_title</li> <li class='date_twitter'>$date</li> </ul>"; } ?> That worked great thanks! I'll keep that in mind for next time Quote Link to comment https://forums.phpfreaks.com/topic/159424-solved-number-of-twitter-posts/#findComment-840976 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.