flickr phpflickr api - php

Overview
I am trying to get a photo feed on to my site using Flickr's api and the phpflickr library. I can successfully get the photoset on to my site, but it shows all the photos from every photoset, what I was hoping to achieve was to show the primary photo from each photoset, and then if the user clicked on the image it would show the full photoset in a lightbox/shadowbox.
My Code
<div id="images" class="tabnav">
<ul class="items">
<?php $count = 1; ?>
<?php foreach ($photosets['photoset'] as $ph_set): ?>
<?php $parentID = $ph_set['parent']; ?>
<?php $photoset_id = $ph_set['id'];
$photos = $f->photosets_getPhotos($photoset_id);
foreach ($photos['photoset']['photo'] as $photo): ?>
<li>
<a rel="shadowbox['<?=$count;?>']" href="<?= $f->buildPhotoURL($photo, 'medium') ?>" title="<?= $photo['title'] ?>">
<img src="<?= $f->buildPhotoURL($photo, 'rectangle') ?>" alt="<?= $photo['title'] ?>" width="210" height="160" title="<?= $photo['title'] ?>" />
<h3><?=$ph_set['title']?></h3>
<p><?=$ph_set['description'];?></p>
</a>
</li>
<?php endforeach; ?>
<?php $count++; ?>
<?php endforeach; ?>
</ul>
</div>
Another Attempt
I have also tried calling the getPhotos function differently, instead of sending it without any parameters I sent it with parameters
$photos = $f->photosets_getPhotos($photoset_id, NULL, NULL, 1, NULL);
The above code stopped the showing all the photos from each photoset and started showing just the primary image, but it also stopped making the rest of the photos accesible to me.
Is there something I can do to make this work? I am totally out iof ideas.
Regards and thanks

I came up with this soltion, thought I would post it in case anyone else hits this problem,
<?php $count = 1; ?>
<?php foreach ($photosets['photoset'] as $ph_set): ?>
<?php $parentID = $ph_set['parent']; ?>
<li>
<?php $photoset_id = $ph_set['id'];
$photos = $f->photosets_getPhotos($photoset_id);
foreach ($photos['photoset']['photo'] as $photo): ?>
<?php if($parentID == $ph_set['parent']): ?>
<a rel="lightbox[album<?=$count;?>]" href="<?= $f->buildPhotoURL($photo, 'medium') ?>" title="<?= $photo['title'] ?>">
<?php endif;?>
<img src="<?= $f->buildPhotoURL($photo, 'rectangle') ?>" alt="<?= $photo['title'] ?>" width="210" height="160" title="<?= $photo['title'] ?>" />
<h3><?=$ph_set['title']?></h3>
<?php if($ph_set['description'] != null) :?>
<p><?=$ph_set['description'];?></p>
<?php endif; ?>
<?php if($parentID == $ph_set['parent']): ?>
</a>
<?php endif;?>
<?php endforeach; ?>
</li>
<?php $count++; ?>

What you'll probably want to do is starting by iterating through the whole array and grouping each album into a separate array first and making a special array for your album's main photo.
Then you can easily iterate through the arrays to display each album and the code becomes much more maintainable.

Related

PHP foreach - Creating multple searchs in the same page

Firstly, I am a total php newby.
Secondly, below is the php header plus corresponding recursive commands for 2 photo lightboxes that are in the same html page.
Without the lines
getRecords() as $Title_row){ ?>
The page shows shows the first picture that is held in the external db table in the lightbox correctly.
Yet when I add the line below to add all the other entries in each table
getRecords() as $Title_row){ ?>
the page goes white and the browser html return is empty.
As I do not really understand what I am doing, I am stuck. Any suggestions would be very welcome.
<?php
$Title_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title_findCriterions = array('Order_web'=>'*',);
foreach($Title_findCriterions as $key=>$value) {
$Title_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title_find,'Title',50);
$Title_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title_result = $Title_find->execute();
if(FileMaker::isError($Title_result)) fmsTrapError($Title_result,"error.php");
fmsSetLastPage($Title_result,'Title',50);
$Title_row = current($Title_result->getRecords());
?>
<?php
$Title1_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title1_findCriterions = array('Order_web'=>'*',);
foreach($Title1_findCriterions as $key=>$value) {
$Title1_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title1_find,'Title',50);
$Title1_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title1_result = $Title1_find->execute();
if(FileMaker::isError($Title1_result)) fmsTrapError($Title1_result,"error.php");
fmsSetLastPage($Title1_result,'Title',50);
$Title1_row = current($Title1_result->getRecords());
?>
<!DOCTYPE html>
<!-- Lightbox Gallery -->
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<!-- Lightbox Gallery End-->
You just missed out the closing brackets :
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>

opencart make table of categories insted of carousel

I am just trying to remake manufacturers carousel so that it will show categories with their images. Part of it I have done. Now i jast want to show them in table 4 in a row. Here is the code that is file catalog/view/module/carousel.tpl/
<div id="carousel<?php echo $module; ?>" class="owl-carousel">
<div class="category">
<table>
<?php if($categories) { ?>
<?php $count = 0;?>
<?php foreach ($categories as $category) { ?>
<?php if($count % 4 == 1){?>
<tr>
<?php}?>
<td>
<a href="<?php echo $category['href']; ?>" <?php echo $category['name']; ?></a>
<img src="<?php echo $category['image'] ?>" alt="<?php echo $category['name']; ?>" title="<?php echo $category['name']; ?>" class="img-thumbnail" />
<p><?php echo $category['name']?>
</td>
<?php if($count % 4 == 0){?>
</tr>
<?php}?>
<?php } ?>
<?php } ?>
</table>
</div>
</div>
<script type="text/javascript"><!--
$('#carousel<?php echo $module; ?>').owlCarousel({
items: 15,
autoPlay: 1000000,
navigation: false,
navigationText: ['<i class="fa fa-chevron-left fa-5x"></i>', '<i class="fa fa-chevron-right fa-5x"></i>'],
pagination: false
});
--></script>
As a result of it I am getting error unexpected end of file. What am I doing wrong? Are their better solutions? I am using opencart version 2.0.1.1
You need to make some minor changes and this will work:
<?php if($count % 4 == 0){?>
</tr>
<?php } ?> //here you need to change
$count++;
Give the space after <?php tag. due to this the error occurs. There is require a space after this tag.
And you are increasing the value of $count.

Page goes blank after adding to PHP foreach

Hello after I add some code to this PHP foreach the page goes blank and all I can see is a round black dot at the top left of screen.
My website is in Joomla3 and I am trying to customize a module. my site is http://get2gethersports.com
I have a recent post module that only shows the articles title.
that code is posted below
<?php if ($items) { ?>
<ul class="rsblog-recent-module unstyled<?php echo $params->get('moduleclass_sfx',''); ?>">
<?php foreach ($items as $item) { ?>
<li>
<a <?php echo $opener; ?> href="<?php echo JRoute::_('index.php?option=com_rsblog&view=post&id='.RSBlogHelper::sef($item->id,$item->alias).$Itemid,false); ?>">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>
I would like to add an image abocve like the blog feed on http://vape-co.com
So I navigated to the component and saw the call for the image. which is posted below:
<div class="rsblog-entry-content">
<?php if ($this->item->image) { ?>
<div class="rsblog-entry-image">
<img class="rsblog-entry-thumb img-polaroid" src="<?php echo JURI::root().'components/com_rsblog/assets/images/blog/'.$this->item->image; ?>?nocache=<?php echo uniqid(''); ?>" alt="<?php echo $this->escape($this->item->title); ?>">
</div>
<?php } ?>
but whenever i add it or a snippet of it to the previous code it breaks....
Any ideas why it is breaking the page and how to fix it?
I tried adding in new li tags. Just adding the PHP part above the a link etc...
CODE UPDATE----
<?php if ($items) { ?>
<ul class="rsblog-recent-module unstyled<?php echo $params->get('moduleclass_sfx',''); ?>">
<?php foreach ($items as $item) { var_dump($item);?>
<li>
<div class="rsblog-entry-content">
<?php if ($this->item->image) { ?>
<div class="rsblog-entry-image">
<img class="rsblog-entry-thumb img-polaroid" src="<?php echo JURI::root().'components/com_rsblog/assets/images/blog/'.$this->item->image; ?>?nocache=<?php echo uniqid(''); ?>" alt="<?php echo $this->escape($this->item->title); ?>">
</div>
</div>
<?php } ?>
<a <?php echo $opener; ?> href="<?php echo JRoute::_('index.php?option=com_rsblog&view=post&id='.RSBlogHelper::sef($item->id,$item->alias).$Itemid,false); ?>">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>
Try $item->image instead of $this->item->image
Correct code. Looks like it just needed some reduction.
<?php if ($items) { ?>
<ul class="rsblog-recent-module unstyled<?php echo $params -> get('moduleclass_sfx',''); ?>">
<?php foreach ($items as $item) { ?>
<li>
<?php if($item->image != '') ?>
<img src="components/com_rsblog/assets/images/blog/<?php echo $item->image;?>" alt="<?php echo $item->title. "logo";?>" width="100px"/>
<br/>
<a <?php echo $opener; ?> href="<?php echo JRoute::_('index.php?option=com_rsblog&view=post&id='.RSBlogHelper::sef($item->id,$item->alias).$Itemid,false); ?>">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>

Magento getting this error: Fatal error: Call to a member function getAttributeText() on a non-object

I am getting the error above in a new template I created in order to show the manufacturer's image. I am using this in the view.phtml file and it works just fine. But since this is custom, I figured there would be problems. Hopefully I can figure this one out.
Here is my current code:
<?php
$layer = Mage::getSingleton('catalog/layer');
$category = $layer->getCurrentCategory();
$currentCategoryId = $category->getId();
$children = Mage::getModel('catalog/category')->getCategories($currentCategoryId);
$product = $this->getProduct();
$brand = $product->getAttributeText('manufacturer');
?>
<div class="landing-page nested-container">
<?php foreach ($children as $category): ?>
<div class="vertical-section grid12-4 mobile-grid-half">
<a href="<?php echo $category->getRequestPath(); ?>">
<img class="center-block" alt="<?php echo $category->getName(); ?>" src="<?php echo $this->getBaseUrl()."media/catalog/category/".Mage::getModel('catalog/category')->load($category->getId())->getThumbnail(); ?>" />
<div class="caption category-boxes-logo full-width">
<?php echo '<img src="'.$this->getBaseUrl().'media/wysiwyg/infortis/brands/'.str_replace(' ', '-', strtolower($brand)).'.jpg" alt="'.$brand.'"></a>' ?>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
You may only call getProduct() for a block which supports it. That generally means a descendant of Mage_Catalog_Block_Product_Abstract although there are others. When creating a block you can specify any type that meets your needs.
<block type="catalog/product_view" template="path/to/your/template.phtml" />
These blocks get their product object from the registry, which is only set for product pages by the catalog controller. If you have to use another block type which does not have a getProduct() function then you can access the registry directly.
$product = Mage::registry('current_product');
It seems to me that you need the manufacturer from products in a given category, and there are several categories to inspect. I assume any product from a category will do. This does not require the block to be a catalog/product_view type.
<?php
$layer = Mage::getSingleton('catalog/layer');
$category = $layer->getCurrentCategory();
$children = $category->getChildrenCategories();
?>
<div class="landing-page nested-container">
<?php foreach ($children as $category): ?>
<!-- Load a product brand per category -->
<?php $product = $category->getProductCollection()->getFirstItem() ?>
<?php $brand = $product ? $product->getAttributeText('manufacturer') : 'default' ?>
<div class="vertical-section grid12-4 mobile-grid-half">
<a href="<?php echo $category->getRequestPath(); ?>">
<img class="center-block" alt="<?php echo $category->getName(); ?>" src="<?php echo $this->getBaseUrl()."media/catalog/category/".$category->getId()->getThumbnail(); ?>" />
<div class="caption category-boxes-logo full-width">
<?php echo '<img src="'.$this->getBaseUrl().'media/wysiwyg/infortis/brands/'.str_replace(' ', '-', strtolower($brand)).'.jpg" alt="'.$brand.'"></a>' ?>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
I figured out what I can do. I just used the product name as they should be matching anyway and used the same string I was trying to use for the Manufacturer. I am posting my answer for anyone who may want an answer down the road:
<?php
$layer = Mage::getSingleton('catalog/layer');
$category = $layer->getCurrentCategory();
$currentCategoryId = $category->getId();
$children = Mage::getModel('catalog/category')->getCategories($currentCategoryId);
?>
<div class="landing-page nested-container">
<?php foreach ($children as $category): ?>
<div class="vertical-section grid12-4 mobile-grid-half">
<a href="<?php echo $category->getRequestPath(); ?>">
<img class="center-block" alt="<?php echo $category->getName(); ?>" src="<?php echo $this->getBaseUrl()."media/catalog/category/".Mage::getModel('catalog/category')->load($category->getId())->getThumbnail(); ?>" />
<div class="caption category-boxes-logo full-width">
<img src="<?php echo $this->getBaseUrl().'media/wysiwyg/infortis/brands/'.str_replace(' ', '_', strtolower($category->getName())).'.png' ?>" alt="<?php echo $category->getName(); ?>">
</div>
</a>
</div>
<?php endforeach; ?>
</div>
I also just used a normal block type of core/template instead of what was suggested in a previous answer. This worked like a charm for me.

Wordpress Facebook Album Plugin

I am currently using a Wordpress plugin called Facebook Page Album and below is the example code for showing the Facebook page albums list and I'm trying to convert it into Wordpress short code but I'm not sure how I should go about it as I'm not to familiar with Wordpress but I can only seem to use the Return statement so how would I go about using the following code with a short code.
<?php
$list = facebook_page_albums_get_album_list();
?>
<ol class="album-list">
<?php foreach ($list as $item) : ?>
<?php
if ($item['type'] != 'normal' || $item['name'] == 'Cover Photos') continue;
?>
<li class="album">
<?php if ($thumb = $item['cover_photo_data']):?>
<div class="album-thumb">
<a href="<?php echo add_query_arg('id', $item['id']);?>">
<img src="<?php echo $thumb['picture'];?>"/>
</a>
</div>
<?php endif; ?>
<div class="album-info">
<h5><?php echo $item['name'];?></h5>
<div class="counts">
<div class="photos-count"><?php echo $item['count'];?></div>
<?php if (!empty($thumb['comments'])) :?><div class="comments-count"><?php echo count($thumb['comments']['data']);?></div><?php endif;?>
<?php if (!empty($thumb['likes'])) :?><div class="likes-count"><?php echo count($thumb['likes']['data']);?></div><?php endif;?>
</div>
</div>
</li>
<?php endforeach;?>
</ol>

Categories