Pass acf fields to Leaflet JS - php

I found this example on the internet that comes pretty close to what I want to do.
I have some ACF fields with the latitude and longitude of some markers, I am trying to show all the markers of the custom post type place in the same map.
But I only get 1, what am I doing wrong?
I think is something related with the marker div
<?php /* Template Name: Demo Page Template */ get_header(); ?>
<h1 class="main-title"><?= post_type_archive_title(); ?></h1>
<section class="list-cases">
<div class="container">
<div class="row position-relative">
<?php
$args = array(
'post_type' => 'lugar',
'posts_per_page' => 10,
);
$query = new WP_Query( $args );
?>
<?php $counter = 1; ?>
<?php while( $query->have_posts() ) : $query->the_post() ?>
<div class="item-case-<?= $counter ?> col-md-12" data-hover="<?= $counter ?>" data-aos="fade-up"
data-aos-duration="2000">
<div class="case-container">
<?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
<p><?php the_field('subtitle') ?></p>
<p><?php the_field('address') ?></p>
<p><strong>Latitud:</strong> <?php the_field('lat') ?></p>
<p><strong>Longitud:</strong> <?php the_field('lon') ?></p>
</div>
</div>
<?php $counter++; ?>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</div>
</section>
<style>
#map,
#acf-map {
height: 500px;
}
</style>
<div id="map" style="width: 600px;">
</div>
<div class="marker" data-lat="<?php echo the_field('lat') ?>" data-lng="<?php the_field('lon'); ?>"
data-title="<?php the_field('subtitle') ?>" data-url="<?php echo 'link'; ?>"
data-category="<?php echo 'category'; ?>"></div>
<script>
$(document).ready(function () {
var map = L.map('map').setView([39.8410802, -0.1191397], 8);
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox',
maxZoom: 18,
id: 'mapbox/streets-v11',
tileSize: 512,
zoomOffset: -1,
accessToken: 'pk.eyJ1IjoiamFtYWxkb2xzIiwiYSI6ImNrYmF2bGowOTBycGEyeG84b2F2NGlsYWkifQ.9rqymFnsW79aCkAFGCo0XQ'
}).addTo(map);
var marker = [];
$.each($('.marker'), function () {
var lat = $(this).attr('data-lat');
var lng = $(this).attr('data-lng');
var name = $(this).attr('data-title');
var link = $(this).attr('data-url');
console.log('Marker es: ' + marker);
marker = [name, lat, lng, link];
console.log('Y ahora es: ' + marker);
console.log(marker);
});
var markers = [marker];
console.log(markers);
console.log(markers.length);
for (var i = 0; i < markers.length; i++) {
marker = new L.marker([markers[i][1], markers[i][2]])
.bindPopup(markers[i][0])
.addTo(map);
}
});
</script>

Please make sure that you are echo-ing the custom field values.
Example: data-lat="<?php echo get_field('lat'); ?>" and data-lat="<?php echo get_field('lon'); ?>"

You need to put the div.marker into the loop to display multiple markers with the custom lat-long values.
<?php while( $query->have_posts() ) : $query->the_post() ?>
<div class="marker"
data-lat="<?php echo get_field( 'lat' ) ?>"
data-lng="<?php echo get_field( 'lon' ); ?>"
data-title="<?php echo get_field( 'subtitle' ) ?>"
data-url="<?php echo 'link'; ?>"
data-category="<?php echo 'category'; ?>" >
</div>
<?php endwhile; wp_reset_postdata(); ?>
Also, I would modify your javascript so it will look like this:
var markers = [];
$.each($('.marker'), function () {
var marker = [];
var lat = $(this).attr('data-lat');
var lng = $(this).attr('data-lng');
var name = $(this).attr('data-title');
var link = $(this).attr('data-url');
console.log('Marker es: ' + marker);
marker = [name, lat, lng, link];
console.log('Y ahora es: ' + marker);
console.log(marker);
markers.push( marker );
});
console.log(markers);
console.log(markers.length);
for (var i = 0; i < markers.length; i++) {
marker = new L.marker([markers[i][1], markers[i][2]])
.bindPopup(markers[i][0])
.addTo(map);
}

Related

Slider not visible in PHP but in HTML works

I am making a shortcode of a slider that shows my WP featured posts and that has the possibility to open the details of each post through a hidden div. The slider is based on this one from w3schools (from which you can see the code and test online from this address: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow
The problem is that the slider is only visible in php once I click the next arrow and from there it works correctly. I don't know why, since in HTML it works fine.
The error apppears: Cannot read property 'style' of undefined in
slides[slideIndex-1].style.display = "block";
My CSS:
#slider {
width: 70%;
margin: auto;
position: relative;
font-size: 15px;
}
.slide {display: none;}
My PHP:
<?php $query = new WP_Query( $args );
ob_start();?>
<div id="slider" class="slider">
<div class="arrows">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a></div>
<?php
while( $query->have_posts() ) :
$query->the_post();
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post-
>ID), '');
$featuredID = get_post_thumbnail_id();?>
<div class="slide fade" id="slide">
<h2 class="zz-sc-jscss"><?php the_title(); ?></h2>
By <?php the_author(); ?> on <?php echo get_the_date( 'l, F d, Y' );
?>
<?php echo the_post_thumbnail();?>
<?php
echo "<div"; echo ' class="n"'; echo "id=".$featuredID.">";
$info = $featuredID;echo "</div>";
?> <div class="open">
<?php echo get_post_field('post_content', $post->ID);?>
<span class="cerrar">X</span></div></div>
<?php endwhile;
wp_reset_postdata();
return ob_get_clean();
}
My JS:
var slideIndex = 1;
showSlides(slideIndex);
// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
}
// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("slide");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex-1].style.display = "block";
}
The problem seems to be in the "slider" div, it does not seem to be closed. Also try moving it after the slide generation loop.
<div id="slider" class="slider"></div> <--missing
<div class="arrows">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>

javascript slider not working

I have this slider in a wordpress theme that it's not working. I have done all the settings right and it won't slide. Automatically or manually. From what I see eveyrthing seems tobe correct. I have also followed all the manufacturer instructions but can't seem to sort it out. Here is the website: www.casavulturului.com
<?php if ( !$paged && get_option('woo_featured') == "true" ) { ?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#loopedSlider").loopedSlider({
<?php
$autoStart = 0;
$slidespeed = 600;
if ( get_option("woo_slider_auto") == "true" )
$autoStart = get_option("woo_slider_interval") * 1000;
else
$autoStart = 0;
if ( get_option("woo_slider_speed") <> "" )
$slidespeed = get_option("woo_slider_speed") * 1000;
?>
autoStart: <?php echo $autoStart; ?>,
slidespeed: <?php echo $slidespeed; ?>,
autoHeight: true
});
});
</script>
<?php } ?>
<div id="sliderWrap">
<div class="innerwrap">
<div id="loopedSlider">
<?php $img_pos = get_option('woo_featured_img_pos'); ?>
<?php $saved = $wp_query; query_posts('suppress_filters=0&post_type=slide&order=ASC&orderby=date&showposts=20'); ?>
<?php if (have_posts()) : $count = 0; $postcount = $wp_query->post_count; ?>
<div class="container">
<div class="slides">
<?php while (have_posts()) : the_post(); ?>
<?php if (!woo_image('return=true')) continue; // Don't show slides without image ?>
<?php $count++; ?>
<div id="slide-<?php echo $count; ?>" class="slide">
<div class="slide-content <?php if($img_pos == "Left") { echo "fr"; } else { echo "fl"; } ?>">
<h2 class="slide-title">
<?php the_title(); ?>
<?php if ($postcount > 1) echo '<span class="controlsbg"> </span>'; ?>
</h2>
<p><?php the_content(); ?></p>
</div><!-- /.slide-content -->
<?php if (woo_image('return=true')) { ?>
<div class="image <?php if($img_pos == "Left") { echo "fl"; } else { echo "fr"; } ?>">
<?php woo_image('width=515&height=245&class=feat-image&link=img'); ?>
</div>
<?php } ?>
<div class="fix"></div>
</div>
<?php endwhile; ?>
</div><!-- /.slides -->
<?php if($count > 1) { ?>
<ul class="nav-buttons <?php if($img_pos == "Left") { echo "right"; } else { } ?>">
<li id="p"></li>
<li id="n"></li>
</ul>
<?php } ?>
</div><!-- /.container -->
<div class="fix"></div>
<?php else : ?>
<p class="note"><?php _e( 'Please add some "Slides" to the featured slider.', 'woothemes' ); ?></p>
<?php endif; $wp_query = $saved;?>
</div><!-- /#loopedSlider -->
</div>
</div><!-- /#sliderWrap -->
JQUERY Code:
(function(jQuery) {
jQuery.fn.loopedSlider = function(options) {
var defaults = {
container: '.container',
slides: '.slides',
pagination: '.pagination',
containerClick: false, // Click container for next slide
autoStart: 0, // Set to positive number for auto start and interval time
restart: 0, // Set to positive number for restart and restart time
slidespeed: 100, // Speed of slide animation
fadespeed: 100, // Speed of fade animation
autoHeight: false // Set to positive number for auto height and animation speed
};
this.each(function() {
var obj = jQuery(this);
var o = jQuery.extend(defaults, options);
var pagination = jQuery(o.pagination+' li a',obj);
var m = 0;
var t = 1;
var s = jQuery(o.slides,obj).children().size();
var w = jQuery(o.slides,obj).children().outerWidth();
var p = 0;
var u = false;
var n = 0;
var interval=0;
var restart=0;
jQuery(o.slides,obj).css({width:(s*w)});
jQuery(o.slides,obj).children().each(function(){
jQuery(this).css({position:'absolute',left:p,display:'block'});
p=p+w;
});
jQuery(pagination,obj).each(function(){
n=n+1;
jQuery(this).attr('rel',n);
jQuery(pagination.eq(0),obj).parent().addClass('active');
});
if (s!=1) { // WooThemes add
jQuery(o.slides,obj).children(':eq('+(s-1)+')').css({position:'absolute',left:-w});
} // WooThemes add
if (s>3) {
jQuery(o.slides,obj).children(':eq('+(s-1)+')').css({position:'absolute',left:-w});
}
if(o.autoHeight){autoHeight(t);}
jQuery('.next',obj).click(function(){
if(u===false) {
animate('next',true);
if(o.autoStart){
if (o.restart) {autoStart();}
else {clearInterval(sliderIntervalID);}
}
} return false;
});
jQuery('.previous',obj).click(function(){
if(u===false) {
animate('prev',true);
if(o.autoStart){
if (o.restart) {autoStart();}
else {clearInterval(sliderIntervalID);}
}
} return false;
});
if (o.containerClick) {
jQuery(o.container ,obj).click(function(){
if(u===false) {
animate('next',true);
if(o.autoStart){
if (o.restart) {autoStart();}
else {clearInterval(sliderIntervalID);}
}
} return false;
});
}
You're using the slide on the "#loopedslider" element:
jQuery("#loopedSlider").loopedSlider({
But that div holds a container with slides, instead of the slides itself. So you have two options:
1) remove the container
OR
2) switch the slider to the element holding the slides:
jQuery(".slides").loopedSlider({

JQuery + Wordpress PHP variable

I'm using the jquery cycle to create a slideshow in my Wordpress template. The "pager" is creating buttons that overlay the slideshow and rollover advances the slides. The trouble I'm running into is that I need the rollover to stay the same, but I also need to set an href so that clicking on the buttons takes the user to a specific page.
I need to retrieve the variable $target from my slideshow for the href.
I need the onclick to make the button clickable.
As I stated above, I'm new at this and it's quite possible that this is terrible code/can't be done/I'm a moron.
My jquery:
<script src="<?php bloginfo('stylesheet_directory'); ?>/scripts/jquery.cycle.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
if ( $('.slides > .slide').size() > 1 ) {
$('.slides')
.cycle({
timeout: 6000,
speed: 1000,
pager: '#slides #mainNav',
pauseOnPagerHover: 200,
pagerEvent: 'mouseover',
pause: true,
pagerAnchorBuilder: function(idx, slide) {
var slideImage = $(slide).find('img');
var slideTitle = slideImage.attr('title');
var slideURL = "<?php echo $target; ?>";
return '<li>' + slideTitle + /* '<br /><span class="description">' + slideDescr + '</span>*/'</li>';
}
});
}
});
</script>
and my Wordpress slideshow:
<?php if ( is_front_page() && $slides = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'slide')) ) : ?>
<div id="mainImg">
<div id="slides">
<div class="slides">
<?php foreach ($slides as $slide) : ?>
<?php $title = $slide->post_title; ?>
<?php $content = wpautop($slide->post_content); ?>
<?php $description = get_post_meta($slide->ID, 'description', true); ?>
<?php $thumb = get_the_post_thumbnail($slide->ID, 'slide', array('title' => $title, 'alt' => $description)); ?>
<?php $url = get_post_meta($slide->ID, '_slide_url', true); ?>
<?php $target = (get_post_meta($slide->ID, '_slide_url_blank', true)) ? 'target="_blank"' : ''; ?>
<div class="slide">
<?php if ($url) : ?>
<a href="<?php echo $url; ?>" <?php echo $target; ?>><?php echo $thumb; ?></a>
<?php else: ?>
<?php echo $thumb; ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<div id="mainNav"></div>
</div>
</div><!--end mainImg-->
<?php endif; ?>
Thank you in advance for your help.
Where you have:
var slideURL = "<?php echo $target; ?>"
Replace it with:
var slideURL = $(slide).find('a').attr('target');
What you are doing above is getting the slide object, finding the 'a' tag in the slide, and then getting the "target" attribute of the 'a' tag. This value is then assigned to the slideURL variable (which will either be '_blank' or undefined). For more information on how to use jQuery to get HTML elements and/or their attributes, you should familiarise yourself more with jQuery's Traversing and Attributes methods.
You should never mix Javascript code with PHP or even HTML code anyway. Read up more on "Unobtrusive JavaScript".

JQuery not replacing content after AJAX GET call (PHP)

Once change INPUT value, content is replaced with a spinner and "Please Wait..." message, and once get response from GET I want to replace the spinner / message with new HTML returned however the new HTML returned is not replacing spinner / message.
The (dynamic PHP) HTML is below followed.
<script type="text/javascript">
$(document).ready( function() {
$( '#submit' ).click( function( e ) {
e.preventDefault();
});
});
</script>
<script type="text/javascript">
$(document).ready( function() {
$( '.basket-item' ).children( 0 ).children( 1 ).change( function( e ) {
e.preventDefault();
var q = $( this ).val();
var id = $( this ).parent().children( 0 ).val();
var elem = $( this ); // var content = elem.parent().parent().parent().html();
elem.parent().parent().parent().html( '<div class="basket-item item-border" style="width:896px;text-align:center;"><p class="para"><img src="<?php echo $this -> get( '__baseuri' ); ?>/media/images/spinner.gif" />Please wait...</p></div>' );
var url = '<?php echo $this -> get( '__baseuri' ); ?>shop/adjust/' + id + '/?quantity=' + q;
$.get( url, function( data ) {
elem.parent().parent().parent().html( data );
});
});
});
</script>
<h1>Shopping Basket</h1>
<div>
<div class="basket-item" style="width:512px;text-align:left;"><p>Product / Item</p></div>
<div class="basket-item"><p>Quantity</p></div>
<div class="basket-item"><p>Price £</p></div>
<div class="basket-item"><p>Total £</p></div>
</div>
<?php if( $this -> has( 'records' ) ): ?>
<form
method="post"
action="#"
accept-charset="utf-8">
<?php foreach( $this -> get( 'records' ) as $record ): ?>
<div>
<div class="basket-item item-border" style="width:512px;text-align:left;">
<p class="para">
<img
width="48"
height="48"
alt="<?php echo $record -> get( 'name' ); ?> (£<?php echo $record -> get( 'price' ); ?>)"
src="<?php echo $this -> get( '__baseuri' ); ?>media/images/products/generic/<?php echo $record -> get( 'image' ); ?>.jpg" />
<?php echo $record -> get( 'name' ); ?></p>
</div>
<div class="basket-item item-border">
<p>
<input type="hidden" name="product" value="<?php echo $record -> get( 'tainted' ); ?>" />
<input type="text" name="quantity" size="3" maxlength="3" value="<?php echo $record -> get( 'quantity' ); ?>" />
</p>
</div>
<div class="basket-item item-border"><p><?php echo $record -> get( 'price' ); ?></p></div>
<div class="basket-item item-border"><p> </p></div>
</div>
<?php endforeach; ?><div style="clear:both;"></div>
<div>
<div class="basket-item item-border" style="width:768px;text-align:right;"><p>Grant Total £ </p></div>
<div class="basket-item item-border" style="width:128px;text-align:center;"><p>14.91</p></div>
</div>
<div>
<div style="margin:0%;padding:16px 0%;width:896px;text-align:left;"><p>
<input id="submit" type="submit" value="Checkout&nbsp>>" />
</p></div>
</div>
</form>
<?php else: ?>
<div>
<div class="basket-item" style="width:896px;text-align:center;"><p>Please add one or more items to your shopping basket.</p></div>
</div>
<?php endif; ?>
Your url is not constructed correctly.
var url = '<?php echo $this -> get( '__baseuri' ); ?>shop/adjust/' + id + '/?quantity=' + q;
Probably needs to be.
var base_uri = "<?php echo $this->get('__baseuri') ?>";
var url = base_uri+'shop/adjust/' + id + '/?quantity=' + q;
The URL is quite acceptable and proper once parsed by server so no issues there, also the server returns content as expected the issue is client side only.

Division by zero in code

I have been working on a site. It displays the following error,
Warning: Division by zero in
/home/sunshine/public_html/wp-content/themes/DailyDeal/index.php on
line 63
Now I went to check the index.php file but on line 63 I have nothing but a closing brace (})
I would be very thankful if someone could point out the error here(I have tried deactivating all the plugins but the problem still holds).
Below is the complete index.php for the reference,
<?php get_header(); ?>
<script type="text/javascript" >
var root_path_js = '<?php echo get_option('siteurl')."/";?>';
</script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/timer.js"></script>
<script type="text/javascript">
jQuery.noConflict();
function a()
{
return false;
}
jQuery(function() {
jQuery( "#slider-range-min-var" ).slider({
range: "min",
value: jQuery("#sellsqlinfo1").val(),
min: 0,
max: jQuery("#noofcoupon1").val(),
enable: false,
slide: function( event, ui ) {
jQuery("#amount").val("$"+ ui.value );
}
});
jQuery( "#amount" ).val( "$" + jQuery( "#slider-range-min-var" ).slider( "value" ) );
});
</script>
<?php
/* Mail To Friend BOF */
if($_POST['sendact']=='email_frnd') {
require_once (TEMPLATEPATH . '/monetize/send_to_friend/email_friend_frm.php');exit;
}
/* Mail To Friend EOF */
/* Home Page Deal Display BOF */
global $wpdb,$deal_db_table_name;
$postmeta_db_table_name = $wpdb->prefix."postmeta";
$post_db_table_name = $wpdb->prefix."posts";
$destination_path = site_url().'/wp-content/uploads/';
$args = array('numberposts' => 1,'meta_key' =>'is_expired' , 'meta_value' =>'0','post_status' => 'publish','post_type' => 'seller','meta_key' =>'status' , 'meta_value' =>'2' ,'orderby' => 'DESC');
$recent_posts = get_posts( $args );
if(mysql_affected_rows() > 0) { // 1st IF Condition BOF
$post_large = bdw_get_images($destination_path.get_post_meta($post->ID,'file_name',true),'large');
$post_images = bdw_get_images($destination_path.get_post_meta($post->ID,'file_name',true),'thumb'); ?>
<div class="top_content">
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('home_above')) { } else { }?>
</div>
<!-- top content #end -->
<div class="box_header"></div>
<div class="box_bg">
<div class=" box_bottom">
<?php foreach( $recent_posts as $post ){ // foreach loop BOF
if((get_post_meta($post->ID,'status',true) == 2) && (get_post_meta($post->ID,'is_expired',true) == 0)) {
deal_expire_process($post->ID);
$home_deal_id = $post->ID;
global $home_deal_id;
$coupon_website= get_post_meta($post->ID,'coupon_website',true);
$owner_name= get_post_meta($post->ID,'owner_name',true);
$our_price= get_post_meta($post->ID,'our_price',true);
$current_price= get_post_meta($post->ID,'current_price',true);
$sellsql = "select count(*) from $transection_db_table_name where post_id=".$post->ID." and status=1";
$totdiff = $current_price - $our_price;
$percent = $totdiff * 100;
$percentsave = $percent/$current_price;
$sellsqlinfo = $wpdb->get_var($sellsql);
$date = get_post_meta($post->ID,'coupon_end_date_time',true);
$tardate= date("F d, Y H:i:s",get_post_meta($post->ID,'coupon_end_date_time',true));
$stdate= date("F d, Y H:i:s",get_post_meta($post->ID,'coupon_start_date_time',true));
$tardate1= date("F d, Y",get_post_meta($post->ID,'coupon_end_date_time',true));
if(get_post_meta($post->ID,'coupon_end_date_time',true) != "") {
if(date("Y-m-d H:i:s") >= $tardate1 && get_post_meta($post->ID,'enddate',true) != '0' || (get_post_meta($post->ID,'no_of_coupon',true)==$sellsqlinfo)) {
if(get_post_meta($post->ID,'is_expired',true)== '0' || get_post_meta($post->ID,'is_expired',true)== '') {
update_post_meta($post->ID,'is_expired','1');
}
}
} else {
if(get_post_meta($post->ID,'enddate',true) != '0' || (get_post_meta($post->ID,'no_of_coupon',true)==$sellsqlinfo)) {
if(get_post_meta($post->ID,'is_expired',true)== '0' || get_post_meta($post->ID,'is_expired',true)== '') {
update_post_meta($post->ID,'is_expired','1');
}
}
}
$geo_longitude = get_post_meta($post->ID,'geo_longitude',true);
$geo_latitude = get_post_meta($post->ID,'geo_latitude',true);
$shhiping_address = get_post_meta($post->ID,'shhiping_address',true);
$coupon_type = get_post_meta($post->ID,'coupon_type',true);
$no_of_coupon = get_post_meta($post->ID,'no_of_coupon',true); ?>
<div class="content_left"> <a href="<?php the_permalink(); ?>">
<?php if(get_post_meta($post->ID,'file_name',true) != "") { ?>
<img src="<?php echo templ_thumbimage_filter(get_post_meta($post->ID,'file_name',true),'&w=330&h=250&zc=1&q=80');?>" alt="" />
<?php } else { ?>
<img src="<?php echo templ_thumbimage_filter(get_template_directory_uri()."/images/no-image.png",'&w=330&h=250&zc=1&q=80');?>" alt="" />
<?php } ?>
</a> </div>
<div class="content_right">
<span class="title_yellow">Today's Top Cruise Holiday Deal</span>
<h3><?php echo $post->post_title; ?></h3>
<?php if(date("Y-m-d H:i:s")>= date("Y-m-d H:i:s",get_post_meta($post->ID,'coupon_end_date_time',true))){
if(get_post_meta($post->ID,'is_expired',true)=='1' || get_post_meta($post->ID,'no_of_coupon',true)==$sellsqlinfo) {
?>
<div class="i_expire"><?php _e('This deal has','templatic');?><span><?php _e(' expired','templatic');?></span><?php _e('on','templatic');?>
<span><?php echo $tardate1;?></span></div>
<?php }
} else {
if(get_post_meta($post->ID,'coupon_end_date_time',true)){ ?>
<div id="demo" style="pointer-events:none; cursor:default;">
<div id="slider-range-min-var" ></div>
</div>
<div class="deal_time_box">
<div class="time_line"></div>
<div id="countdowncontainer"></div>
<script type="text/javascript">
var dealexpire=new cdtime("countdowncontainer", "<?php echo $tardate; ?>")
dealexpire.displaycountdown("days", formatresults)
</script>
<div class="fr">
<div class="price_main"> <span class="strike_rate"><?php echo get_currency_sym();?><?php echo $current_price;?></span> <span class="rate"><?php echo get_currency_sym();?><?php echo $our_price;?></span> </div>
<?php if(get_post_meta($post->ID,'coupon_type',true) == 1) { ?>
<?php _e(BUY_NOW,'templatic');?>
<?php } else { ?>
<?php _e(BUY_NOW,'templatic');?>
<?php }?>
</div>
</div>
<?php } ?>
<?php } ?>
<!-- Rate Summery BOF -->
<ul class="rate_summery border_bottom">
<li class="rate_current_price"><span><?php _e(CURRENT_PRICE,'templatic');?></span> <strong><small><?php echo get_currency_sym();?></small><?php echo $current_price;?></strong></li>
<li class="rate_our_price"><span><?php _e(OUR_PRICE,'templatic');?></span> <strong><small><?php echo get_currency_sym();?></small><?php echo $our_price;?></strong></li>
<li class="rate_percentage"><span><?php _e(YOU_SAVE,'templatic');?></span> <strong><?php echo #number_format($percentsave,2);?>%</strong></li>
<?php if($sellsqlinfo == 0 ) {
$enddate = explode(" ",$tardate);
$curdate = explode(" ",date("F d, Y H:i:s"));
$enddate= str_replace(",","",$enddate[1]);
$curdate = str_replace(",","",$curdate[1]);
$startdate = explode(" ",$stdate);
$strdate = str_replace(","," ",$startdate[1]);
$curtime = $enddate - $curdate;
$totaltime = ($enddate - $strdate);
$nowremail = $curdate - $strdate; ?>
<input type="hidden" value="<?php echo $nowremail ; ?>" name="sellsqlinfo1" id="sellsqlinfo1"/>
<input type="hidden" value="<?php echo ($enddate - $strdate) ; ?>" name="noofcoupon1" id="noofcoupon1"/>
<?php } else { ?>
<input type="hidden" value="<?php echo $sellsqlinfo; ?>" name="sellsqlinfo1" id="sellsqlinfo1"/>
<input type="hidden" value="<?php echo $no_of_coupon; ?>" name="noofcoupon1" id="noofcoupon1"/>
<?php } ?></li>
</ul>
<?php if(get_post_meta($post->ID,'enddate',true) == '0' && get_option('ptttheme_view_opt') != 'Grid View' && (get_post_meta($post->ID,'status',true) == '1' || get_post_meta($post->ID,'status',true) == '2') ) {
?>
<?php if(get_post_meta($post->ID,'coupon_type',true) == 1) {?>
<?php _e(BUY_NOW,'templatic');?>
<?php } else { ?>
<?php _e(BUY_NOW,'templatic');?>
<?php }
}?>
<!-- Rate Summery EOF -->
<div id="content" class="text_content" ><?php echo "".$post->post_excerpt.""; ?>
<?php _e(get_option('ptthemes_content_excerpt_readmore'));?> </div>
</div>
<!-- Social Network Button Like: twitter,facebook,google + one BOF -->
<div class="share_div index_share_spacer">
<div class="twitt_like"><?php templ_show_twitter_button(); ?></div>
<div class="googleplus">
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<script type="text/javascript">
gapi.plusone.render(gcontent,"href": "<?php the_permalink(); ?>", "state": "on");
gapi.plusone.go("gcontent");
</script>
<div id="gcontent">
<g:plusone href="<?php the_permalink(); ?>" size="medium"></g:plusone>
</div>
</div>
<?php templ_show_facebook_button(); ?>
<?php _e(MAIL_TO_FRIEND,'templatic');?>
</div>
<!-- Social Network Button Like: twitter,facebook,google + one EOF -->
<?php } else { ?>
<div class="content_left">
<h3><?php echo _e(NO_RECENT_DEAL,'templatic'); ?></h3>
</div>
<?php }
} // foreach loop BOF
} // 1st IF Condition EOF
/* Home Page Deal Display EOF */ ?>
</div>
</div>
<!-- main post #end -->
<div class="clear">
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('home_below')) { } else { }?>
</div>
<?php include_once (TEMPLATEPATH . '/monetize/send_to_friend/popup_frms.php');?>
<?php get_footer(); ?>
Your divide by zero is inside the include from line 61. Post that code if you still cant find the problem.
So let's be very careful in our codes having numerical divisions because any number divided by zero is undefined. Try it in any device - your phone, your calculator, etc.
This ternary condition could help, but don't force 0 (zero) to be the value of $percentsave when $current_price equals 0. This will ruin the semantic logic of your application.
$percentsave = ($current_price != 0) ? $percent/$current_price : 'undefined';
However, regarding your query -- why its showing in line 63, perhaps you have a code wrapping with your IDE (php specific codes) and that part of the code can be seen in line 63.

Categories