$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>";
}
I have used this code to display all the available posts, but i want to display just first five posts
我已经使用此代码显示所有可用的帖子,但我想只显示前五个帖子
2 个解决方案
#1
3
According to the tumblr API, you can append a querystring parameter num
to limit the number of posts returned from the API call. I have no personal experience with the Tumblr API, but you might try something like this to limit the number of posts read:
根据tumblr API,您可以附加查询字符串参数num以限制从API调用返回的帖子数。我没有使用Tumblr API的个人经验,但您可以尝试这样的方法来限制读取的帖子数量:
$numPosts = 5;
$feedURL = "http://########.tumblr.com/api/read/?num=$numPosts";
$xml = simplexml_load_file($feedURL);
// etc. etc.
#2
1
Read API docs. http://www.tumblr.com/docs/en/api#api_read
阅读API文档。 http://www.tumblr.com/docs/en/api#api_read
If you give ?num=5
you'll get 5 results.
如果你给?num = 5你会得到5个结果。
On the other hand you can use the following:
另一方面,您可以使用以下内容:
$posts = $xml->posts->post;
$posts = array_slice($posts, 0, 5);
#1
3
According to the tumblr API, you can append a querystring parameter num
to limit the number of posts returned from the API call. I have no personal experience with the Tumblr API, but you might try something like this to limit the number of posts read:
根据tumblr API,您可以附加查询字符串参数num以限制从API调用返回的帖子数。我没有使用Tumblr API的个人经验,但您可以尝试这样的方法来限制读取的帖子数量:
$numPosts = 5;
$feedURL = "http://########.tumblr.com/api/read/?num=$numPosts";
$xml = simplexml_load_file($feedURL);
// etc. etc.
#2
1
Read API docs. http://www.tumblr.com/docs/en/api#api_read
阅读API文档。 http://www.tumblr.com/docs/en/api#api_read
If you give ?num=5
you'll get 5 results.
如果你给?num = 5你会得到5个结果。
On the other hand you can use the following:
另一方面,您可以使用以下内容:
$posts = $xml->posts->post;
$posts = array_slice($posts, 0, 5);