Topic: Facebook Album |
|||
|---|---|---|---|
Posted: 2012-02-05 |
|||
|
User |
Ok looking for some help for an addon I will give for free once done. This is the start of the Facebook addon - plugin: class Plugin_Facebook extends Plugin
{
function images() {
//Set the page name or I
$FBid = $this->attribute('id');
//Get the contents of a Facebook page
$FBpage = file_get_contents('https://graph.facebook.com/'.$FBid.'/albums');
//Interpret data with JSON
$photoData = json_decode($FBpage);
foreach($photoData->data as $data) {
$images = array('id' => $data->id);
return $images;
}
}I added this to my template and only one image shows. Want to see what I am doing wrong on the loop. Thanks for the help. {{facebook:images id="498638085466"}}
<img src="https://graph.facebook.com/{{id}}/picture">
{{/facebook:images}} |
||
| Quote | |||
Posted: 2012-02-05 |
# 1 | ||
|
Admin |
You are overwriting the array on each loop so there is only one item when the function returns. Additionally the return is inside the foreach loop so it returns after the first iteration. What you need to do is initiate the $images variable as an array at the beginning of the function and then append the image value to the array. Like this: class Plugin_Facebook extends Plugin
{
function images()
{
$images = array();
//Set the page name or I
$FBid = $this->attribute('id');
//Get the contents of a Facebook page
$FBpage = file_get_contents('https://graph.facebook.com/'.$FBid.'/albums');
//Interpret data with JSON
$photoData = json_decode($FBpage);
foreach($photoData->data as $data)
{
$images[] = array('id' => $data->id);
}
return $images;
}
}I haven't tested it but that should be close. |
||
| Quote | |||
Posted: 2012-02-05 |
# 2 | ||
|
User |
Jerel you have always been a lifesaver. I had images[] = array('id' => $data->id); originally but did not have the return out of the foreach loop. Thanks again will post the addon when fully done. | ||
| Quote | |||
