I want to show more than one photo - php

<div class="col-lg-6">
<div class="cz-product-gallery">
<div class="cz-preview order-sm-2">
<?php $i = 0;
foreach ($prdGal as $galeri) {
$i++; ?>
<div class="cz-preview-item <?php if ($i == 1) {
echo "active";
} ?>" id="galeri_<?= $galeri->id ?>">
<img class="cz-image-zoom" src="<?= base_url(firstGalleryItem($product->galeri_uniq)) ?>" data-zoom="<?= base_url(firstGalleryItem($product->galeri_uniq)) ?>" alt="<?= $product->urun_ad ?>">
<div class="cz-image-zoom-pane"></div>
</div>
<?php } ?>
</div>
The above code is showing bigphotos
<div class="cz-thumblist order-sm-1">
<?php $i = 0;
foreach ($prdGal as $gal) {
$i++;
$activeClass = $i == 1 ? "active" : "";?>
<a class="cz-thumblist-item <?php if ($i == 1) {
echo "active";
} ?>" href="#galeri_<?= $gal->id ?>">
<img src="<?= base_url(firstGalleryItem($product->galeri_uniq)) ?>"
alt="<?= $product->urun_ad ?>">
</a>
<?php } ?>
</div>
This code shows the small version of the big photos.
The problem here is that even though I upload 2 different photos, I can only take 1 photo. How can I show 2 different photos?

Related

How can I set my for - loop to print images in the HTML - page

I have two images in a folder and their record is in a database so I want to show the images on the page through a for loop. But the problem is that I have classes (left and right) for which I want to define a variable to show images separately, so how can I do. The only problem is with the $val variable.
<div class="col-md-7 wthree-services-bottom-grids">
<?php for ($i = 0; $i < 2; $i++){ $val = ''?>
<div class="wthree-services-<?php echo $val; ?>">
<img src="<?php echo base_url(); ?>uploads/frontend/about_us/<?php echo $about_images[$i]->image; ?>" alt="">
</div>
<?php $val = 'right'; }?>
<!-- <div class="wthree-services-right">
<img src="<?php echo base_url(); ?>uploads/frontend/about_us/<?php echo $about_images[1]->image; ?>" alt="">
</div>-->
<div class="clearfix"> </div>
</div>
I'm not sure if I understand correctly what you're trying to do but does this behave like what you're after?
<div class="col-md-7 wthree-services-bottom-grids">
<?php
for ($i = 0; $i < 2; $i++):
$val = ($i == 0 || $i % 2 == 0 ? 'left': 'right'); ?>
<div class="wthree-services-<?php echo $val; ?>">
<img src="<?php echo base_url(); ?>uploads/frontend/about_us/<?php echo $about_images[$i]->image; ?>" alt="">
</div>
<div class="clearfix"></div>
<?php endfor; ?>

Show random product on homepage through phtml

I have a block being displayed on my homepage which shows a product, whose id we specify. The code on homepage (static block) looks like this:
{{block type="core/template" product_id="2559" template="catalog/product/one_product.phtml"}}
The one_product.phtml file contains this code:
<?php
$productId = $this->getProduct_id();
$product = Mage::getModel('catalog/product')->load($productId); //load product
?>
<div class="product">
<a href="<?php echo $product->getProductUrl() ?>" >
<img class="product-img" src="<?php echo $this->helper('catalog/image')->init($product, 'image'); ?>"alt="<?php echo $this->htmlEscape($product->getName()) ?>" />
</a>
</div>
<div class="product-detail">
<P><?php // echo $this->htmlEscape($product->getName()) ?>
<?php $prod_name = $this->htmlEscape($product->getName()); ?>
<?php
$count_str = strlen($prod_name);
if ($count_str < 40) {
echo $prod_name;
} else {
$offset = 0;
$length = 41;
$prod_name = html_entity_decode($prod_name);
echo htmlentities(mb_substr($prod_name,0,$length,'utf-8')). "...";;
}
?>
</P>
<!--?php $price = $product->getPrice() ; ?-->
<?php $_product = Mage::getModel('catalog/product')->load($product->getId());
$productBlock = $this->getLayout()->createBlock('catalog/product_price');
?>
<span>
<?php echo $productBlock->getPriceHtml($_product); ?>
<?php $tier_price = end($_product->getTierPrice());
if($tier_price !='0'){ ?>
<span>As Low As:</span>
<?php
echo " ₹ ".number_format( $tier_price['price']);
} ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart"
onclick="setLocation('<?php echo Mage::helper('checkout/cart')->getAddUrl($product); ?>')">
</span>
</div>
So basically I want to show random products out of the ones I specify separated by commas. For eg: I specify in the static block product_id="2559,2661,2857,9293" and it should show any one of those 4 products randomly.
What is the way to do that?
Also any way to make it pull products from SKU also? Since we remember all the SKUs but we have to check each product ID everytime we change the product here.
Please excuse me if the question is too basic, I'm not a developer.
You can see it in action at www.giftzila.com
Thanks!
Create a new file called random-product.phtml at app/design/frontend/default/Your_Theme/template/catalog/random-product.phtml then add the following code in that file
<?php
$chosen_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$_productCollection = $this->getLoadedProductCollection();
$number_of_products = $this->getNumProducts();
if (sizeof($_productCollection) < $number_of_products) {
$number_of_products = sizeof($_productCollection);
}
$displayed_products = array();
foreach ($_productCollection as $_product) {
$displayed_products[] = $_product;
}
$random_products = array();
if (sizeof($_productCollection) > 1) {
$random_products = array_rand($displayed_products, $number_of_products);
} else {
$random_products = array('0');
}
?>
<?php if(!$_productCollection->getSize()):?>
<div class="note-msg">
<?=$this->__('There are no products matching the selection.')?>
</div>
<?php else:?>
<div class="main-binder">
<div class="cms-box">
<div class="category-title">
<h2>Random Products</h2>
</div>
<div class="category-products">
<table id="products-grid-table" class="products-grid">
<?php
$k=0;
for ($i=0; $i < $number_of_products; $i++): ?>
<?php if ($k == 0) { ?>
<tr class="first odd">
<?php } if($k==3) { $k=0; ?>
</tr><tr class="first odd even">
<?php } ?>
<td id="td_<?php echo ($k+1); ?>" <?php if($k==3){ ?>class="last"<? } ?> >
<div class="cms-box">
<div id="cont_<?php echo ($k+1); ?>">
<div class="product-name-block">
<?php
$pname=$this->htmlEscape($displayed_products[$random_products[$i]]->getName());
?>
<h3 class="product-name">
<a href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>" title="<?php echo $pname; ?>">
<?php if(strlen($pname) > 28) {echo substr($pname,0,25)."...";}else {echo $pname;}?>
</a></h3>
</div>
<div class="image-box">
<a class="product-image" href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>"> <img src="<?php echo $this->helper('catalog/image')->init($displayed_products[$random_products[$i]], 'small_image')->resize(140);?>" alt="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>" title="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>"/> </a>
</div>
<div class="cms-price-box" style=" text-align:center;">
<span class="regular-price" id="product-price-37">
<span class="price" ><?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol().$displayed_products[$random_products[$i]]->getPrice(); ?></span>
</span>
</div>
<div class="button-row" style="text-align:center;">
<button onclick="setLocation('<?php echo $displayed_products[$random_products[$i]]->getProductUrl();?>')" class="button" type="button"><span><span><span>Details</span></span></span></button>
<button onclick="setLocation('<?php echo $this->getUrl('')."/checkout/cart/add?product=".$displayed_products[$random_products[$i]]->getId()."&qty=1" ?>')" class="button"><span><?php echo $this->__('Add to Cart') ?></span></button>
</div>
</div>
</div></td>
<?php $k++; ?>
<?php endfor;?>
</tr>
</table>
</div>
</div>
</div>
<?php endif;?>
Now call block in your cms home page by adding following code:-
{{block type="catalog/product_list" category_id="3" num_products="8" template="catalog/random-product.phtml"}}

PHP loop need to create new div every 5 elements

I've got a forech loop that displays 50 logos. But what I need is another loop that creates a new div(.autogrid_wrapper .cte .block) every 5 images.
<div class="autogrid_wrapper cte block">
<div class="inner">
<?php foreach($this->entries as $entry): ?>
<figure class="image_container">
<img src="<?php echo $entry->field('logo')->generate(); ?>" title="<?php echo $entry->field('name')->value(); ?>" alt="<?php echo $entry->field('name')->value(); ?>" >
</figure>
<?php endforeach; ?>
</div>
</div>
I hope you guys can help me.
A simple counter could help -
<div class="autogrid_wrapper cte block">
<div class="inner">
<?php
$i = $j = $k = 0;
foreach($this->entries as $entry):
$i++;
$class = '';
if($j === 0) {
$class = 'first';
}
$j++;
$html = '';
if($i % 5 === 0) {
$k++;
$j = ($i - (5 * $k));
$class = 'last';
$html = "</div></div>
<div class='autogrid_wrapper cte block'><div class='inner'>";
}
?>
<figure class="image_container <?php echo $class; ?>">
<img src="<?php echo $entry->field('logo')->generate(); ?>" title="<?php echo $entry->field('name')->value(); ?>" alt="<?php echo $entry->field('name')->value(); ?>" >
</figure>
<?php
echo $html;
endforeach;
?>
</div>
</div>

Arrange divs on new row every third time

I have this most annoying problem; I'm trying to arrange three divs on a row, and then new row, and another three divs and so on, like this:
<div class="container">
<div class="row">
<div class="col-sm-1">1</div>
<div class="col-sm-1">2</div>
<div class="col-sm-1">3</div>
</div>
<div class="row">
<div class="col-sm-1">4</div>
<div class="col-sm-1">5</div>
<div class="col-sm-1">6</div>
</div>
</div>
As for this accepted answer,
There is one catch: 0 % 3 is equal to 0. This could result in
unexpected results if your counter starts at 0.
So how would i implement this into this code:
<div class="col-md-8">
<?php
foreach($this->movies->movie_data as $key => $movie){
$string = file_get_contents("http://example.com/?t=" . urlencode($movie->movie_titel). "&y=&plot=short&r=json");
$result = json_decode($string);
if($result->Response == 'True'){
?>
<div class="col-sm-4">
<?php if($result->Poster == 'N/A') : ?>
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
<?php else: ?>
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo $result->Poster; ?>" class="img-responsive img-thumbnail"></a>
<?php endif; ?>
<div><b><?php echo $result->Title; ?></b></div>
<div><i><?php // echo $result->Plot; ?></i></div>
</div>
<?php }else{ ?>
<div class="col-sm-4">
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
<div><b><?php echo $movie->movie_titel ?></b></div>
<div class="plot"><i><?php //echo 'N/A' ?></i></div>
</div>
<?php }}} ?
</div>
For some reason, divs is arranged like this:
My question: How do I arrange thumbnails on a new row, every third time?
Found the answer in the other Q... Didn't read, sorry about that.
<?php }
if (($key + 1) % 3 == 0) { ?>
</div>
<?php }
}} ?>

adding a links to my banner images in a banner rotator code

I've searched but the results I found weren't useful to my case.
I have this code that shows rotating banners on my page. It pulls images from a folder and I can add more images through admin.
I would like to make those images clickable, so they can take you to a page on my site.
I don't know PHP, but I can copy paste well and do have some logic.
I would appreciate if you could modify the existing code, so that it works.
Thank you
<div class="baner">
<div class="baner_icon">
</div>
<div id="rotator">
<ul>
<?php
$baners = TopBaners::model()->recently()->findAll();
$i = 0;
foreach ($baners as $value) {
if ($i == 0) {
?><li class="show"><img src="/i/<?php echo $value->file ?>" width="999" height="300px" alt="IMG"></li><?PHP
} else {
?><li><img src="/i/<?php echo $value->file ?>" height="300px" width="999" alt="IMG"></li><?PHP
}
$i++;
}
?>
</ul>
</div>
</div>
<div class="baner">
<div class="baner_icon">
</div>
<div id="rotator">
<ul>
<?php
$baners = TopBaners::model()->recently()->findAll();
$i = 0;
foreach ($baners as $value) {
if ($i == 0) {
?><li class="show"><img src="/i/<?php echo $value->file ?>" width="999" height="300px" alt="IMG"></li><?PHP
} else {
?><li><img src="/i/<?php echo $value->file ?>" height="300px" width="999" alt="IMG"></li><?PHP
}
$i++;
}
?>
</ul>
</div>
</div>

Categories