From 515928b8e2da0e46dcb6b7375579c45ba973d98f Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Wed, 24 Feb 2016 22:01:24 +0700 Subject: [PATCH] FIX: Ensure tag cloud widget does not break when there are zero tags --- code/widgets/BlogTagsCloudWidget.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code/widgets/BlogTagsCloudWidget.php b/code/widgets/BlogTagsCloudWidget.php index 550e9f3..7f81e3e 100644 --- a/code/widgets/BlogTagsCloudWidget.php +++ b/code/widgets/BlogTagsCloudWidget.php @@ -90,12 +90,15 @@ class BlogTagsCloudWidget extends Widget } // normalize the tag counts from 1 to 10 - $tagfactor = 10 / $maxTagCount; - foreach ($tags->getIterator() as $tag) { - $normalized = round($tagfactor * ($tag->TagCount)); - $tag->NormalizedTag = $normalized; + if ($maxTagCount) { + $tagfactor = 10 / $maxTagCount; + foreach ($tags->getIterator() as $tag) { + $normalized = round($tagfactor * ($tag->TagCount)); + $tag->NormalizedTag = $normalized; + } } + return $tags; }