$feedURL = 'http://########.tumblr.com/api/read/';
$xml = simplexml_load_file($feedURL);
foreach($xml->posts->post as $post){
$posts = (string) $post->{'photo-caption'};
$img = (string) $post->{'photo-url'};
echo "<div style='width:518px;height:300px;'><div style='width:200px;height:200px;float:left;'>".'<img style="width:200px;height:200px;" src="' . $img . '" />'."</div><div style='width:300px;float:right;'>".$posts."</div></div><br>";
}
我已使用此代码来显示所有可用的帖子,但我只想显示前五个帖子
最佳答案
根据to the tumblr API ,您可以附加查询字符串参数 num
来限制从 API 调用返回的帖子数量。我对 Tumblr API 没有个人经验,但您可以尝试这样的方法来限制阅读的帖子数量:
$numPosts = 5;
$feedURL = "http://########.tumblr.com/api/read/?num=$numPosts";
$xml = simplexml_load_file($feedURL);
// etc. etc.
关于php - 使用 tumblr API 获取前 5 篇帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6653749/