dynamic image path for lightgallery plugin - php

We have already added the code,but only thumb images are displaying.we want natural image path.
I have attached image reference,Please go through this
<div class="<?php echo $class; ?>">
<?php if ($thumb || $images) { ?>
<ul class="thumbnails" id="lightgallery" >
<?php if ($thumb) { ?>
<li class="col-xs-6 col-sm-4 col-md-3 prdbimgImg img-responsive" data-responsive="<?php echo $thumb; ?>" data-src="<?php echo $thumb; ?>" >
<a href="" id="zoom_01">
<img class="img-responsive" src="<?php echo $thumb; ?>" data-zoom-image="<?php echo $popup; ?>">
</a>
</li>
<?php } ?>
<?php if ($images) { ?>
<?php foreach ($images as $image) { ?>
<li class="image-additional img-responsive" data-responsive="<?php echo $image['thumb']; ?>" data-src="<?php echo $image['thumb']; ?>" >
<a href="" data-id="zoom_01">
<img class="img-responsive" src="<?php echo $image['thumb']; ?>" data-zoom-image="<?php echo $popup; ?>">
</a>
</li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
</div>

That's because you're setting your thumbnail to data-src:
data-src="<?php echo $image['thumb']; ?>"
According to the docs, data-src should contain the full image.
If the images are stored in $images and thumbnails in $thumb as you say, then this should do the trick:
<ul id="lightGallery" >
<?php for ($i = 0; $i < count($images); $i++) { ?>
<li data-src="<?php echo $images[$i]; ?>" >
<img src="<?php echo $thumb[$i]; ?>" />
</li>
<?php } ?>
</ul>

Related

ACF PRO Image in Repeater not showing

The images are not showing in front-end. ACF settings screenshot
<?php
if( have_rows('how_it_works_functions') ):
$counter = 0;
while( have_rows('how_it_works_functions') ) : the_row();
$counter++;
?>
<div class="step<?php echo $counter; ?>">
<div class="row section-content">
<?php if($counter == 2) { ?>
<div class="col-md-8 image">
<img class="skip-lazy" src="<?php get_sub_field('how_it_works_functions_image')['url']; ?>" alt="<?php get_sub_field('how_it_works_functions_image')['alt']; ?>">
</div>
<div class="col-md-4 text">
<h3 data-aos="fade-left" data-aos-offset="300" data-aos-duration="1000"><?php the_sub_field('how_it_works_functions_name'); ?></h3>
<p data-aos="fade-up" data-aos-offset="100" data-aos-duration="1000"><?php the_sub_field('how_it_works_functions_description'); ?></p>
</div>
<?php } else { ?>
<div class="col-md-4 text">
<h3 data-aos="fade-right" data-aos-offset="300" data-aos-duration="1000"><?php the_sub_field('how_it_works_functions_name'); ?></h3>
<p data-aos="fade-up" data-aos-offset="100" data-aos-duration="1000"><?php the_sub_field('how_it_works_functions_description'); ?></p>
</div>
<div class="col-md-8 image">
<img class="skip-lazy" src="<?php get_sub_field('how_it_works_functions_image')['url']; ?>" alt="<?php get_sub_field('how_it_works_functions_image')['alt']; ?>">
</div>
<?php } ?>
</div>
</div>
<?php
endwhile;
endif;
?>
I already check the var_dump and it is getting the correct url but I still have broken image in front-end.
You need to echo that field.
Like this based on your code:
<img class="skip-lazy" src="<?php echo get_sub_field( 'how_it_works_functions_image' )['url']; ?>" alt="<?php echo get_sub_field( 'how_it_works_functions_image' )['alt']; ?>">
Alternative effective way:
<?php
$image = get_sub_field( 'how_it_works_functions_image' );
?>
<img class="skip-lazy" src="<?php echo esc_attr( $image['url'] ); ?>" alt="<?php echo esc_attr( $image['alt'] ); ?>">
Try out the above solution and let me know if it works or not.

Jump to a specific tab in WordPress

I have a code which works on my localhost but does not work when I implement it on my live site, which is hosted on WordPress.
I have the below code on another page:
<div class="smaller-col col-xs-6 col-md-3 product-thumb">
<a href='<?php echo "/the-pods#{$product_id}"; ?>' target="_blank" class="thumbnail">
<img class="img-responsive animated pulse eds-on-hover" src="<?php echo $product_image; ?>" width="120" height="120" alt="Hello Paisa">
</a>
<p><?php echo $product_tagline; ?></p>
</div>
The above page links to the page with the code below:
<div id="exTab1" class="">
<ul class="nav nav-pills">
<?php
$counter = 0; while($products->fetch()):
$product_id = $products->field('product_id');
$product_image = wp_get_attachment_url($products->get_field('product_logo.ID'));
?>
<li class="<?php if($counter == 0){ echo 'active'; } ?>">
<a href='<?php echo "#$product_id"; ?>' data-toggle="tab">
<img class="img-responsive" src="<?php echo $product_image; ?>"/>
</a>
</li>
<?php $counter++; endwhile; ?>
</ul>
<div class="tab-content">
<?php
$counter_2 = 0; while($products_2->fetch()):
$product_id_2 = $products_2->field('product_id');
$product_image_2 = wp_get_attachment_url($products_2->get_field('product_logo.ID'));
$product_desc_2 = $products_2->field('product_description');
$product_website_2 = $products_2->field('product_website');
?>
<div class="tab-pane <?php if($counter_2 == 0){ echo 'active'; } ?> fade in" id="<?php echo $product_id_2; ?>">
<?php echo '#' . $product_image_2; ?>
<?php echo "<p style='color:#777;'>" . $product_desc_2 . "</p>";?>
<?php echo $product_website_2; ?>
</div>
<?php $counter_2++; endwhile; ?>
</div>
</div>
<script>
var tabUrl = document.location.toString();
if(tabUrl.match('#')) {
$('.nav-pills a[href="#' + tabUrl.split('#')[1] + '"]').tab('show');
}
$('#nav-pills a').on('shown.bs.tab', function(e) {
window.location.hash = e.target.hash;
});
</script>
How do I implement the navigation part properly on Wordpress?

Display random products on product page of magento every time i refresh the page

I want to Display random products on product page of magento every time i refresh the page.
I have tried finding the answer on google and some of the solutions were to change my list.phtml code.
i have tried replacing
$_productCollection=$this->getLoadedProductCollection();
with
$_productCollection=shuffle($this->getLoadedProductCollection());
or adding
$items = $_productCollection->getitems;
$item = shuffle($items);
but its not working, Even if shuffle() would work on collections (it doesn't), this would only show the same products in a different order. i want my products which are on the later page to come forward.
Here is my list.phtml code:
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$gallery_helper = $this->helper('productlistgallery/data');
// Chech if Tm_SpecialPriceCountdown module is installed
if (Mage::helper('core')->isModuleEnabled('Tm_SpecialPriceCountdown')) {
$spcd_helper = $this->helper('specialpricecountdown/data');
$currDate = $spcd_helper->currDate();
}
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php echo $this->getToolbarHtml() ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<ul class="products-list" id="products-list">
<?php foreach ($_productCollection as $_product): ?>
<li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>" itemscope itemtype="http://schema.org/product">
<?php // Product Image ?>
<div class="product-image-container">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image" itemprop="url" style="width:<?php echo $gallery_helper->getListData('image_width') + 20; ?>px;">
<img id="product-collection-image-<?php echo $_product->getId(); ?>" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($gallery_helper->getListData('image_width'), $gallery_helper->getListData('image_height')); ?>" width="<?php echo $gallery_helper->getListData('image_width'); ?>" height="<?php echo $gallery_helper->getListData('image_height'); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" itemprop="image" />
</a>
<?php
if($gallery_helper->getListData('active')):
?>
<ul class="product-thumbs">
<?php
$count_thumbs = 1;
foreach ($_product->getMediaGalleryImages() as $image):
if($count_thumbs <= 3):
?>
<li class="product-thumb">
<a href="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $image->getFile())->resize($gallery_helper->getListData('image_width')); ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $image->getFile())->resize($gallery_helper->getListData('thumb_size_w'), $gallery_helper->getListData('thumb_size_h')); ?>" width="<?php echo $gallery_helper->getListData('thumb_size_w'); ?>" height="<?php echo $gallery_helper->getListData('thumb_size_h'); ?>" alt="" />
</a>
</li>
<?php endif ?>
<?php $count_thumbs++; ?>
<?php endforeach ?>
</ul>
<?php endif ?>
</div>
<?php // Product description ?>
<div class="product-shop">
<div class="f-fix">
<div class="product-primary">
<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
<h2 class="product-name" itemprop="name"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product) ?>
<?php endif; ?>
<?php
// Provides extra blocks on which to hang some features for products in the list
// Features providing UI elements targeting this block will display directly below the product name
if ($this->getChild('name.after')) {
$_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
foreach ($_nameAfterChildren as $_nameAfterChildName) {
$_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
$_nameAfterChild->setProduct($_product);
echo $_nameAfterChild->toHtml();
}
}
?>
<div class="desc std">
<div itemprop="description"><?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?></div>
<?php echo $this->__('Learn More') ?>
</div>
</div>
<div class="product-secondary">
<?php echo $this->getPriceHtml($_product, true) ?>
<?php if(!$_product->canConfigure() && $_product->isSaleable()): ?>
<p class="actions">
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
</p>
<?php elseif($_product->getStockItem() && $_product->getStockItem()->getIsInStock()): ?>
<p class="actions"><a title="<?php echo $this->__('View Details') ?>" class="button btn-details" href="<?php echo $_product->getProductUrl() ?>"><span><span><?php echo $this->__('View Details') ?></span></span></a></p>
<?php else: ?>
<p class="actions availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a title="<?php echo $this->__('Add to Wishlist') ?>" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist tooltips"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <a title="<?php echo $this->__('Add to Compare') ?>" href="<?php echo $_compareUrl ?>" class="link-compare tooltips"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
<div class="label-product">
<?php if($_product->getNew()){echo '<span class="new">'.$this->__('New').'</span>'; }?>
<?php if($_product->getSale()){echo '<span class="sale">'.$this->__('Sale').'</span>'; }?>
</div>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
<?php else: ?>
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php //$_columnCount = $this->getColumnCount(); ?>
<?php $_columnCount = 3; ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php
$_productId = $_product->getId();
if ($i++%$_columnCount==0): ?>
<ul class="products-grid row">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?> col-xs-12 col-sm-4" itemscope itemtype="http://schema.org/product">
<div class="wrapper-hover">
<div class="product-image-container">
<?php if ($gallery_helper->getGridData('type_hover') == 'carusel_images'): ?>
<?php include("include_gallery.phtml"); ?>
<?php else: ?>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image" itemprop="url">
<img id="product-collection-image-<?php echo $_productId; ?>" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($gallery_helper->getGridData('image_width'), $gallery_helper->getGridData('image_height')); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" width="<?php echo $gallery_helper->getGridData('image_width'); ?>" height="<?php echo $gallery_helper->getGridData('image_height'); ?>" itemprop="image" />
</a>
<?php endif ?>
<?php if($gallery_helper->getGridData('type_hover') == 'thumbnails'): ?>
<ul class="product-thumbs">
<?php $count_thumbs = 1; foreach ($_product->getMediaGalleryImages() as $image): ?>
<?php if($count_thumbs <= 3): ?>
<li class="product-thumb">
<a href="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $image->getFile())->resize($gallery_helper->getGridData('image_width')); ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $image->getFile())->resize($gallery_helper->getGridData('thumb_size_w'), $gallery_helper->getGridData('thumb_size_h')); ?>" width="<?php echo $gallery_helper->getGridData('thumb_size_w'); ?>" height="<?php echo $gallery_helper->getGridData('thumb_size_h'); ?>" alt="" />
</a>
</li>
<?php endif; ?>
<?php $count_thumbs++; ?>
<?php endforeach ?>
</ul>
<?php endif ?>
</div>
<div class="product-details">
<h2 class="product-name" itemprop="name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
<h3 style="font-size:14px;text-transform:capitalize;"><?php echo $this->htmlEscape($_product->getData('artistname')); ?></h3>
<?php echo $this->getPriceHtml($_product, true) ?>
<?php if(isset($spcd_helper) && $spcd_helper->isEnabledGridList()): ?>
<?php
$setDate = $spcd_helper->countdownTime($_product);
if ($setDate > 0):
if ($currDate < $setDate): ?>
<div id="special_countdown_<?php echo $_product->getId(); ?>" class="special_countdown"></div>
<script type="text/javascript">
setCountdown("<?php echo $setDate; ?>", "<?php echo $_product->getId(); ?>");
</script>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php
// Provides extra bloc->keepFrame(false)s on which to hang some features for products in the list
// Features providing UI elements targeting this block will display directly below the product name
if ($this->getChild('name.after')) {
$_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
foreach ($_nameAfterChildren as $_nameAfterChildName) {
$_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
$_nameAfterChild->setProduct($_product);
echo $_nameAfterChild->toHtml();
}
}
?>
<div class="wrapper-hover-hiden">
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<div class="actions">
<?php if(!$_product->canConfigure() && $_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php elseif($_product->getStockItem() && $_product->getStockItem()->getIsInStock()): ?>
<a title="<?php echo $this->__('View Details') ?>" class="button btn-details" href="<?php echo $_product->getProductUrl() ?>"><span><span><?php echo $this->__('View Details') ?></span></span></a>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><?php echo $this->__('Add to Wishlist') ?></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<?php endif; ?>
</ul>
</div>
</div>
</div>
<div class="label-product">
<?php if($_product->getNew()){echo '<span class="new">'.$this->__('New').'</span>'; }?>
<?php if($_product->getSale()){echo '<span class="sale">'.$this->__('Sale').'</span>'; }?>
</div>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
<?php endif; ?>
<?php
// Provides a block where additional page components may be attached, primarily good for in-page JavaScript
if ($this->getChild('after')) {
$_afterChildren = $this->getChild('after')->getSortedChildren();
foreach ($_afterChildren as $_afterChildName) {
$_afterChild = $this->getChild('after')->getChild($_afterChildName);
//set product collection on after blocks
$_afterChild->setProductCollection($_productCollection);
echo $_afterChild->toHtml();
}
}
?>
First Override your list.phtml file in your custom theme.
Add this code in your list.phtml file.
$productArray = iterator_to_array($_productCollection);
shuffle($productArray);
and add this $productArray in foreach loop.
<?php foreach ($productArray as $_product): ?>
cacheable="false" in your catalog_category_view.xml file.
<block class="Magento\Catalog\Block\Product\ListProduct"
name="category.products.list"
as="product_list"
template="Magento_Catalog::product/list.phtml"
cacheable="false"
>
The collection is an iterator and not an array, array functions do not work with iterators. but you can convert it.
Try this:-
$productCollection=$this->getLoadedProductCollection();
$productArray = iterator_to_array($productCollection);
$items = shuffle($productArray);

How to make the thumbnail pager dynamically in bxslider?

I'm using bxslider to show images from the database, it works but the thumbnails of the caroussels isn't clickable.
This is the code what I use;
<?php if ($object->fotos->has()): ?>
<ul class="bxslider">
<?php foreach ($object->fotos as $foto): ?>
<?php $photo = wp_get_attachment_image_src($foto->ID, 'large'); ?>
<li><img src="<?= $photo[0] ?>"></li>
<?php endforeach; ?>
</ul>
<div id="bx-pager">
<?php foreach ($object->fotos as $foto): ?>
<?php $photo = wp_get_attachment_image_src($foto->ID, 'thumbnail'); ?>
<a data-slide-index="0" href=""><img src="<?= $photo[0] ?>" /></a>
<?php endforeach; ?>
</div>
<?php endif; ?>
I tried:
<div id="bx-pager">
<?php foreach ($object->fotos as $foto): ?>
<?php $photo = wp_get_attachment_image_src($foto->ID, 'thumbnail'); ?>
<a data-slide-index="0" href=""><img src="<?= $photo[0] ?>" /></a>
<a data-slide-index="1" href=""><img src="<?= $photo[1] ?>" /></a>
<a data-slide-index="2" href=""><img src="<?= $photo[2] ?>" /></a>
<?php endforeach; ?>
</div>
This is clickable but it doesn't show the image. How can I make the thumbnail images clickable?
Check This
http://jsfiddle.net/L5S2B/2/
I think it should be work, If its not than feel to get back
Below is the HTML and grab Javascript from Fiddle
<!-- slider 1 -->
<ul class="bxslider">
</ul>
<!-- custom controls -->
<div class="bxslider-controls">
<a class="pull-left" href="#">PREV</a>
<a class="pull-right" href="#">NEXT</a>
</div>

Conditional in Foreach Statement

I'm trying to make use of twitter bootstrap carosel in OpenCart. I only want the first banner to have the div class "active." How would I go about this?
<div id="homepage" class="carousel slide">
<div class="carousel-inner">
<?php foreach ($banners as $banner) { ?>
<div class="item active">
<?php if ($banner['link']) { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
</div>
<?php } else { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
</div>
<?php } ?>
<?php } ?>
</div>
Thanks in advance
For example, use additional variable $flag
<div id="homepage" class="carousel slide">
<div class="carousel-inner">
<?php
$flag = 0;
foreach ($banners as $banner) { ?>
<div class="item <?php echo ($flag==0?"active":"");?>">
<?php if ($banner['link']) { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
</div>
<?php } else { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
</div>
<?php } ?>
<?php
$flag=1;
} ?>
</div>
You can also uses the array's key, than you can choose the first or the second etc...
<div id="homepage" class="carousel slide">
<div class="carousel-inner">
<?php
$flag = 0;
foreach ($banners as $key => $banner) { ?>
<div class="item <?php echo ($key == 0?"active":"");?>">
<?php if ($banner['link']) { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
</div>
<?php } else { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
</div>
<?php } ?>
<?php
$flag=1;
} ?>
</div>

Categories