在 WordPress 主题中除以零错误 [英] Division by zero error in WordPress Theme

查看:28
本文介绍了在 WordPress 主题中除以零错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近购买了一个 WordPress 主题,它可以展示精美的照片图库,但在主页上出现以下错误.

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.

警告:第 36 行/home/content/21/4913121/html/studios/wp-content/themes/dt-chocolate/front-gal.php 中被零除

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

警告:第 48 行/home/content/21/4913121/html/studios/wp-content/themes/dt-chocolate/front-gal.php 中被零除

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

以下是第 50 行的代码 - 带有 /**/ 的行是问题所在.任何帮助表示赞赏!

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';

推荐答案

如果你添加了一些代码来检查值不为零,它应该停止这样做,但可能会有更大的问题.

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

和/或

$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

这篇关于在 WordPress 主题中除以零错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆