Jump to a specific tab in WordPress - php

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?

Related

Magento category to owl carousel

This code is displaying only one product from each category, however I want it to display all products from each category in its own owl-carousel.
How can I fix this?
<?php
$categoryIds = array("3","5","6","12","7");
foreach($categoryIds as $categoryId){
$carouselcategoryProducts = $block->getCategoryProductsById($categoryId);
foreach ($carouselcategoryProducts as $carouselproduct) {
/*Get Thumbnail*/
$carouselimageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct');
$carouselproductImage = $carouselimageBlock->getImage($carouselproduct, 'category_page_grid');
?>
<div class="owl-carousel owl-theme">
<h4 class="item">
<a href="<?php echo $carouselproduct->getProductUrl(); ?>">
<div class="product_row2">
<div class="product_column2">
<img class="product_img2" <?php echo $carouselproductImage->toHtml(); ?><i class="far fa-clone compare"></i>
<p class="product_title2"><?php echo $carouselproduct->getName(); ?></p>
<p class="product_price2">€ <?php echo $carouselproduct->getFinalPrice(); ?>,-</p>
</div>
</div>
</a>
</h4>
</div>
<?php
}
}
?>
Fixed the issue.
Correct code:
<?php
$categoryIds = array(3,5,6,12,7);
foreach($categoryIds as $categoryId) :
//echo "<p>category id: </p>$categoryId";
$carouselcategoryProducts = $block->getCategoryProductsById($categoryId);
echo "<div class=\"owl-carousel owl-theme\">";
foreach ($carouselcategoryProducts as $carouselproduct) :
//Get Thumbnail
$carouselimageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct');
$carouselproductImage = $carouselimageBlock->getImage($carouselproduct, 'category_page_grid');
?>
<h4 class="item">
<a href="<?php echo $carouselproduct->getProductUrl(); ?>">
<div class="product_row2">
<div class="product_column2">
<img class="product_img2" <?php echo $carouselproductImage->toHtml(); ?><i class="far fa-clone compare"></i>
<p class="product_title2"><?php echo $carouselproduct->getName(); ?></p>
<p class="product_price2">€ <?php echo $carouselproduct->getFinalPrice(); ?>,-</p>
</div>
</div>
</a>
</h4>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
Correct Code:
$categoryIds = array(3,5,6,12,7);
foreach ($categoryIds as $cat)
{
$_category = $objectManager->create('Magento\Catalog\Model\Category')->load($cat);
echo "<div class=\"owl-carousel owl-theme\">";
$categoryProducts = $_category->getProductCollection()
->addAttributeToSelect('*');
foreach ($categoryProducts as $product) {?>
<h4 class="item">
<a href="<?php echo $product->getProductUrl(); ?>">
<div class="product_row2">
<div class="product_column2">
<img class="product_img2" <?php echo $product->toHtml(); ?><i class="far fa-clone compare"></i>
<p class="product_title2"><?php echo $product->getName(); ?></p>
<p class="product_price2">€ <?php echo $product->getFinalPrice(); ?>,-</p>
</div>
</div>
</a>
</h4>
}
echo "</div>";
}

dynamic image path for lightgallery plugin

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>

Shortcode is moving the_content outside of the article container in WordPress

I've made a shortcode function that returns some Advanced Custom Fields depending on which repeater field is chosen. It displays correctly and in the right order however any content typed underneath the shortcode is moved outside of its <article> container element.
Here is the code:
function boxes_shortcode($atts, $content = null) {
ob_start(); ?>
<div id="boxes">
<div class="box-gutter"></div>
<div class="box-sizer"></div>
<?php while( have_rows('box_repeater') ): the_row();
$image_id = get_sub_field('link_image');
$image_size = 'box-thumbnail';
$image_array = wp_get_attachment_image_src($image_id, $image_size);
$linkImage = $image_array[0]; ?>
<?php if(get_sub_field('box_type') == "box-link"): ?>
<div class="box">
<div class="link-box">
<img src="<?php echo $linkImage; ?>" alt="<?php echo $linkImage['alt']; ?>" />
<a class="caption-wrapper" href="http://www.google.com">
<span id="link-box-content" style="background:<?php the_sub_field('link_background_colour'); ?>">
<h6 style="color:<?php the_sub_field('link_title_colour'); ?>"><?php the_sub_field('link_title'); ?></h6>
<h4 style="color:<?php the_sub_field('link_text_colour'); ?>"><?php the_sub_field('link_text'); ?></h4>
<p style="color:<?php the_sub_field('link_text_colour'); ?>" href="<?php the_sub_field('link_url'); ?>"><?php the_sub_field('link_url_text'); ?> ></p>
</span>
</a>
</div>
</div>
<?php endif;
if(get_sub_field('box_type') == "box-quote"): ?>
<div class="box">
<div class="quote-box">
<div class="quotation-mark"></div>
<h4><?php the_sub_field('quote'); ?></h2>
<p><?php the_sub_field('quote_source'); ?></p>
<?php the_sub_field('quote_link_text'); ?> >
</div>
</div>
<?php endif;
if(get_sub_field('box_type') == "box-twitter"): ?>
<div class="box">
<div class="twitter">
<a class="twitter-timeline" href="<?php the_sub_field('twitter_url'); ?>" data-widget-id="<?php the_sub_field('twitter_widget_id'); ?>" data-chrome="noheader noscrollbar nofooter noborders transparent" data-tweet-limit="<?php the_sub_field('number_of_tweets'); ?>"></a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<a class="twitter-badge" href="<?php the_sub_field('twitter_url'); ?>"></a>
<div class="twitter-bottom">See more ></div>
</div>
</div>
<?php endif;
endwhile;?>
</div>
</div>
</div>
<?php
/* Get the buffered content into a var */
$sc = ob_get_contents();
ob_end_clean();
return $sc;
}
add_shortcode('boxes', 'boxes_shortcode');
Can anyone help solve this mystery? Many thanks.
You have two extra closing <div>'s in your code.
Try this:
function boxes_shortcode($atts, $content = null) {
ob_start(); ?>
<div id="boxes">
<div class="box-gutter"></div>
<div class="box-sizer"></div>
<?php while( have_rows('box_repeater') ): the_row();
$image_id = get_sub_field('link_image');
$image_size = 'box-thumbnail';
$image_array = wp_get_attachment_image_src($image_id, $image_size);
$linkImage = $image_array[0]; ?>
<?php if(get_sub_field('box_type') == "box-link"): ?>
<div class="box">
<div class="link-box">
<img src="<?php echo $linkImage; ?>" alt="<?php echo $linkImage['alt']; ?>" />
<a class="caption-wrapper" href="http://www.google.com">
<span id="link-box-content" style="background:<?php the_sub_field('link_background_colour'); ?>">
<h6 style="color:<?php the_sub_field('link_title_colour'); ?>"><?php the_sub_field('link_title'); ?></h6>
<h4 style="color:<?php the_sub_field('link_text_colour'); ?>"><?php the_sub_field('link_text'); ?></h4>
<p style="color:<?php the_sub_field('link_text_colour'); ?>" href="<?php the_sub_field('link_url'); ?>"><?php the_sub_field('link_url_text'); ?> ></p>
</span>
</a>
</div>
</div>
<?php endif;
if(get_sub_field('box_type') == "box-quote"): ?>
<div class="box">
<div class="quote-box">
<div class="quotation-mark"></div>
<h4><?php the_sub_field('quote'); ?></h2>
<p><?php the_sub_field('quote_source'); ?></p>
<?php the_sub_field('quote_link_text'); ?> >
</div>
</div>
<?php endif;
if(get_sub_field('box_type') == "box-twitter"): ?>
<div class="box">
<div class="twitter">
<a class="twitter-timeline" href="<?php the_sub_field('twitter_url'); ?>" data-widget-id="<?php the_sub_field('twitter_widget_id'); ?>" data-chrome="noheader noscrollbar nofooter noborders transparent" data-tweet-limit="<?php the_sub_field('number_of_tweets'); ?>"></a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<a class="twitter-badge" href="<?php the_sub_field('twitter_url'); ?>"></a>
<div class="twitter-bottom">See more ></div>
</div>
</div>
<?php endif;
endwhile;?>
</div>
<!--/div>
</div-->
<?php
/* Get the buffered content into a var */
$sc = ob_get_contents();
ob_end_clean();
return $sc;
}
add_shortcode('boxes', 'boxes_shortcode');

how i use bootstrap slider in open cart

Is there anyone who try out bootstrap slide with opencart slideshow module?
Here is my code i am trying but getting all active classes. Someone can help me plz.
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<div class="carousel-inner slideshow <?php echo $module; ?>">
<div class="item active">
<?php foreach ($banners as $banner) { ?>
<?php if ($banner['link']) { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
<?php } else { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
<?php } ?>
<?php } ?>
</div>
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div>
</div>
UPD: loop must be like this
<div class="carousel slide" data-ride="carousel">
<div class="carousel-inner slideshow<?php echo $module; ?>">
<?php foreach ($banners as $banner) { ?>
<?php if ($banner['link']) { ?>
<div class="item"><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" /></div>
<?php } else { ?>
<div class="item"><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" /></div>
<?php } ?>
<?php } ?>
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"><span class="bootstrap_left"></span></a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"><span class="bootstrap_right"></span></a>
</div>
</div>
and jquery
<script type="text/javascript"><!--
$(document).ready(function() {
$('.item:first-child').addClass('active');
$('.carousel').carousel();
});
--></script>
As you can see in your 3rd line you have
<div class="item active"> .
You need to include this inside the loop of your php.
Then create a condition that if it is the first item, set its class as item active and then in your else statement just item.
Try work it out with this example code.
<?php $i = 1; ?>
<?php foreach ($rows as $row): ?>
<?php $item_class = ($i == 1) ? 'item active' : 'item'; ?>
<div class="<?php echo $item_class; ?>">
<a href="<?php echo $row['url']; ?>">
<img src="<?php echo $row['image']; ?>" alt="<?php echo $row['title']; ?>" />
</a>
</div>
<?php $i++; ?>
<?php endforeach; ?>
Have you refer or check the html version outputted of your code. If simillar
to what should bootstrap carousel setup should be?
Please do refer with it . BOOTSTRAP CAROUSEL
Else refer to this fiddle JSFIDDLE DEMO
Carousel Script
// invoke the carousel
$('#myCarousel').carousel({
interval: 3000
});
/* SLIDE ON CLICK */
$('.carousel-linked-nav > li > a').click(function() {
// grab href, remove pound sign, convert to number
var item = Number($(this).attr('href').substring(1));
// slide to number -1 (account for zero indexing)
$('#myCarousel').carousel(item - 1);
// remove current active class
$('.carousel-linked-nav .active').removeClass('active');
// add active class to just clicked on item
$(this).parent().addClass('active');
// don't follow the link
return false;
});
/* AUTOPLAY NAV HIGHLIGHT */
// bind 'slid' function
$('#myCarousel').bind('slid', function() {
// remove active class
$('.carousel-linked-nav .active').removeClass('active');
// get index of currently active item
var idx = $('#myCarousel .item.active').index();
// select currently active item and add active class
$('.carousel-linked-nav li:eq(' + idx + ')').addClass('active');
});
Manchary had the right idea. I have tested this, and run it in my Opencart.
Here's the full code to add to:
catalog/view/theme/yourtheme/template/module/carousel.tpl
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<?php
$i = 0;
foreach ($banners as $banner) {
echo "<li data-target=\"#myCarousel\" data-slide-to=\"".$i."\" class=\"indicator\"></li>\n";
$i++;
}
?>
</ol>
<!-- slides -->
<div class="carousel-inner">
<?php foreach ($banners as $banner) { ?>
<?php if ($banner['link']) { ?>
<div class="item"><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" /></div>
<?php } else { ?>
<div class="item"><img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" /></div>
<?php } ?>
<?php } ?>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function($){
$('#myCarousel ol.carousel-indicators li:first').addClass('active');
$('#myCarousel .item:first').addClass('active');
$('#myCarousel').carousel({
interval: 8000
});
});
//]]>
</script>
Note* If jQuery document ready is causing grief, you can try
window.onload = function() {
// code here
}
Hope this helps someone.

Link to a CMS product page in Magento

I am looking for some advice on how best to link to a CMS product page from a template phtml file. I need to generate a link using 'foreach' as each product will have its own CMS product page. For example I have six products currently being displayed on the homepage I would like to have an 'order now' button that will take the user to the 'add to cart' page (view.phtml) and a 'more info?' button that will take the user to the CMS page for that product... is there a way to achieve this?
Here's the code from new.phtml
<div class="new-product-content">
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<h3 class="subtitle new-products"><?php echo $this->__('HOT PRODUCTS') ?></h3>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul>
<?php endif ?>
<li class="thumb<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" ><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(175) ?>" width="175" height="175" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
</a>
<div class="caption">
<h4 class="product-name"> <?php $_productName = $this->helper('core/string')->truncate($this->htmlEscape($_product->getName()),20,'...', $_remainder, true); ?>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productName ?>">
<?php echo $_productName ?><?php echo $this->__('™'); ?></a></h4>
<?php echo $this->getPriceHtml($_product, true, '-new') ?>
<div class="clearfix"></div>
<div class="desc">
<?php $sdesc = $_product->getShortDescription();
$sdesc = trim($sdesc);
$limit = 180;
if (strlen($sdesc) > $limit) {
$sdesc = substr($sdesc, 0, strrpos(substr($sdesc, 0, $limit), ' '));
} ?>
<?php echo $sdesc."..."; ?>
</div>
<div class="clearfix"></div>
<div class="btn-group">
<button class="btn" type="button" title="<?php echo $this->__('Add to Cart') ?>" onclick="setLocation('<?php echo $this->getProductUrl($_product) ?>')"><?php echo $this->__('Order now...') ?></button>
<!--I NEED TO CHANGE THE DESTINATION OF THIS LINK <button class="btn" type="button" title="<?php echo $this->__('More info') ?>" onclick="setLocation('<?php echo $this->getProductUrl($_product) ?>')"><?php echo $this->__('More info?') ?></button> --->
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
</ul>
<div class="clearfix"></div>
<?php endif ?>
<script type="text/javascript">
$j('.thumb li').last().css('border-right', 'none');
</script>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endforeach; ?>
<?php endif; ?>
<div class="clearfix"></div>
</div>
Try something like, you need to get the 'url key' for the cms pages
<button class="btn" type="button" title="<?php echo $this->__('More info') ?>" onclick="setLocation('<?php echo $this->getUrl('url key'); ?>')"><?php echo $this->__('More info?') ?></button>

Categories