Jump to content

[SOLVED] Number of Twitter Posts?


cahamilton

Recommended Posts

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 } ?>

Link to comment
https://forums.phpfreaks.com/topic/159424-solved-number-of-twitter-posts/
Share on other sites

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>";
}
?>

 

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.