MyBB Community Forums

Full Version: Change Poll Bar Colors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
The aim of this tutorial is to Change poll bar colors according to the percent of votes it received. This require to edit one template and one core file edit.

Open ./showthread.php and find;
$imagerowwidth = $imagewidth + 10;
and Add the following code just Beneath it;
				// Poll Votes Colors
				if ($percent == 10 || $percent < 10 && $percent > 0)
				{
					$pollbg = '#FF0000';
				}
				elseif ($percent >= 11 && $percent < 20)
				{
					$pollbg = '#33CC33';
				}
				elseif ($percent >= 20 && $percent < 30)
				{
					$pollbg = '#FF33CC';
				}
				elseif ($percent >= 30 && $percent < 40)
				{
					$pollbg = '#66CCFF';
				}
				elseif ($percent >= 40 && $percent < 50)
				{
					$pollbg = '#FFFF99';
				}
				elseif ($percent >= 50 && $percent < 60)
				{
					$pollbg = '#33CCCC';
				}
				elseif ($percent >= 60 && $percent < 70)
				{
					$pollbg = '#990033';
				}
				elseif ($percent >= 70 && $percent < 80)
				{
					$pollbg = '#FF9900';
				}
				elseif ($percent >= 80 && $percent < 90)
				{
					$pollbg = '#669999';
				}
				elseif ($percent >= 90)
				{
					$pollbg = '#9933FF';
				}

Save the file.

Now Go to: ACP > Templates > Your theme's templates > Showthread templates > showthread_poll_resultbit > and find;
<td class="{$optionbg}"><img src="{$theme['imgdir']}/pollbar-s.gif" alt="" /><img src="{$theme['imgdir']}/pollbar.gif" width="{$imagewidth}" height="10" alt="{$percent}%" title="{$percent}%" /><img src="{$theme['imgdir']}/pollbar-e.gif" alt="" /></td>
and Change it into;
<td class="{$optionbg}">
<div>
<div style="background-color: #fff; border: 1px solid black; width:50%; margin-top: 1px; font-size: 7px;">
<div style="background-color: {$pollbg}; color: #000000; font-weight:bold; max-width:100%;  width:{$percent}%; height:10px;">
&nbsp;&nbsp;&nbsp;{$percent}%
</div>
</div>
</div>
</td>

Now it'll look like this;
[attachment=24633]

You may change these colors to suite your taste.

Now if you want to add these colors on Poll results page, then here is how;

Similarly open ./poll.php and find;
eval("\$polloptions .= \"".$templates->get("polls_showresults_resultbit")."\";");

Now add the following code just Above it;
               // Poll Votes Colors
                if ($percent == 10 || $percent < 10 && $percent > 0)
                {
                    $pollbg = '#FF0000';
                }
                elseif ($percent >= 11 && $percent < 20)
                {
                    $pollbg = '#33CC33';
                }
                elseif ($percent >= 20 && $percent < 30)
                {
                    $pollbg = '#FF33CC';
                }
                elseif ($percent >= 30 && $percent < 40)
                {
                    $pollbg = '#66CCFF';
                }
                elseif ($percent >= 40 && $percent < 50)
                {
                    $pollbg = '#FFFF99';
                }
                elseif ($percent >= 50 && $percent < 60)
                {
                    $pollbg = '#33CCCC';
                }
                elseif ($percent >= 60 && $percent < 70)
                {
                    $pollbg = '#990033';
                }
                elseif ($percent >= 70 && $percent < 80)
                {
                    $pollbg = '#FF9900';
                }
                elseif ($percent >= 80 && $percent < 90)
                {
                    $pollbg = '#669999';
                }
                elseif ($percent >= 90)
                {
                    $pollbg = '#9933FF';
                }

Now open ACP > templates > Your theme's templates > Poll templates > "polls_showresults_resultbit" template and find;
<td class="{$optionbg}" width="{$imagerowwidth}"><img src="{$theme['imgdir']}/pollbar-s.gif" alt="" /><img src="{$theme['imgdir']}/pollbar.gif" width="{$imagewidth}" height="10" alt="{$percent}%" title="{$percent}%" /><img src="{$theme['imgdir']}/pollbar-e.gif" alt="" /><br />{$userlist}</td>
and Change it into;
<td class="{$optionbg}">
<div>
<div style="background-color: #fff; border: 1px solid black; width:50%; margin-top: 1px; font-size: 7px;">
<div style="background-color: {$pollbg}; color: #000000; font-weight:bold; max-width:100%;  width:{$percent}%; height:10px;">
&nbsp;&nbsp;&nbsp;{$percent}%
</div>
</div>
</div>{$userlist}</td>
Awesome,need this Smile thanks friend.
It's okay, but is there any way to get the "%" sign into the box instead of sticking out?
(2011-11-10, 02:00 AM)ZouX Wrote: [ -> ]It's okay, but is there any way to get the "%" sign into the box instead of sticking out?

Yes, I've updated the first post.
I just realized that the poll does not reflect the colors while using the plug in "Poll on index"

In the actual thread, it does. But not on our index or portal page.

Is there any way to fix that?

You can see our poll at tortoiseinfo.org
The same situation ... no colors Huh
(2011-11-09, 11:34 AM)Yaldaram Wrote: [ -> ]The aim of this tutorial is to Change poll bar colors according to the percent of votes it received. This require to edit one template and one core file edit.
I think that require edit two template (showthread_poll_resultbit and polls_showresults_resultbit) and two core file edit (showthread.php and polls.php).

What exactly must change in this templates and php files?
What's your suggestion for this?
This only covers the polls on showthread pages. If you guys need to change the poll colors on Poll pages, then let me know. I'll update the first post.
(2011-11-12, 04:27 AM)Yaldaram Wrote: [ -> ]This only covers the polls on showthread pages. If you guys need to change the poll colors on Poll pages, then let me know. I'll update the first post.

Yes Yaldaram, we need that.. Wink Thank You.Smile
Pages: 1 2