Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.