Division by zero error in WordPress Theme

I recently bought a WordPress theme that does a fancy gallery display of photos and it has been getting the following errors on the homepage.

Warning: Division by zero in /home/content/21/4913121/html/stsudios/wp-content/themes/dt-chocolate/front-gal.php on line 36

Read More

Warning: Division by zero in /home/content/21/4913121/html/stsudios/wp-content/themes/dt-chocolate/front-gal.php on line 48

The following is the code through line 50 – the lines with /**/ are the trouble ones. Any help is appreciated!

<?php

global $postgallery;
$show = $postgallery->get_post_option('show');
$arr = $postgallery->get_post_option('show_'.$show);
$arr = explode(",", $arr);
$arr = (array)$arr;

//$myterms = get_terms('dt_gallery_cat');
$myterms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy'=> 'dt_gallery_cat'));

$images = array();

global $term, $h;

foreach ($myterms as $term)
{

   if ($show == "all")
   {

   }
   elseif ($show == "only")
   {
      if ( !in_array( $term->term_id, $arr ) )
         continue;
   }
   elseif ($show == "except")
   {
      if ( in_array( $term->term_id, $arr ) )
         continue;
   }

   $term->pic = wp_get_attachment_image_src( $term->image_id, 'full' );

   $k = $term->pic[1] / $term->pic[2];

   /**/$term->pic = $term->pic[0];/**/

   $size = taxonomy_get_size( $term->term_id );
   if ($size == "s")
      $w = 220;
   if ($size == "m")
      $w = 460;
   if ($size == "l")
      $w = 700;

   /**/$h = ceil($w / $k);/**/

   $term->pic = get_template_directory_uri().'/thumb.php?src='.$term->pic.'&amp;w='.$w.'&amp;h='.$h.'&amp;zc=1';

Related posts

Leave a Reply

1 comment

  1. If you add in some code to check that the values aren’t zero it should stop it doing this, but there may be bigger problems.

    if ( $term->pic[1] == 0 || $term->pic[2] == 0 ) return
    

    and / or

    $h = ( $w > 0 && $k > 0 ) ? ceil($w / $k) : 0;
    

    These values probably shouldn’t be zero though, so there is likely something else going wrong. Perhaps your images are not in a format readable by the code… or you haven’t uploaded any yet