Hey everyone,
Today we are going to discuss how to modify your Xenforo install in order to show who has voted and how many votes their are before you vote on a poll. Now this can come in handy if you want to just see how a poll is doing that you haven’t voted in.
So how do you do this you ask? Well we have to do a bit of modification to a core file. Please before you do this back up your Xenforo installation just in case something goes wrong after you do this. So what are we editing then?
Well we are going to edit poll_block_vote in the Templates edit section of your Admin Panel.
So navigate to Appearance -> Templates -> poll_block_vote. It looks like this:
Once you click on it you will see this:
So what code are we looking for? This one:
<ol class="pollOptions"> <xen:foreach loop="$poll.responses" key="$pollResponseId" value="$response"> <li class="pollOption"> <label> <xen:if is="{$poll.multiple}"> <input type="checkbox" name="response_multiple[]" value="{$pollResponseId}" /> <xen:else /> <input type="radio" name="response" value="{$pollResponseId}" /> </ xen: if> {$Response.response} </ label> </ li> </ Xen: foreach> </ol>
We are going to replace it with another code which is the following:
<ol> <xen:foreach loop="$poll.responses" key="$pollResponseId" value="$response"> <li class="pollOption"> <ol class="pollResults"> <li class="pollResult {xen:if $response.hasVoted, voted}"> <xen:if is="{$response.hasVoted}"> <div class="votedIconCell" title="{xen:phrase your_vote}">*</div> <xen:else /> <div class="votedIconCell"></div> </xen:if> <h3 class="optionText" {xen:if $response.hasVoted, 'title="{xen:phrase your_vote}"'}> <xen:if is="{$poll.multiple}"><input type="checkbox" name="response_multiple[]" value="{$pollResponseId}" /><xen:else /><input type="radio" name="response" value="{$pollResponseId}" /></xen:if> {$response.response} </h3> <div class="barCell"> <span class="barContainer"> <xen:if is="{$response.response_vote_count}"><span class="bar" style="width: {xen:calc "100 * {$response.response_vote_count} / {$poll.voter_count}"}%"></span></xen:if> </span> </div> <div class="count"> <xen:if is="{$poll.public_votes} AND {$response.response_vote_count}"> <a href="{xen:link threads/poll/results, $thread, 'poll_response_id={$pollResponseId}'}" class="concealed OverlayTrigger">{xen:phrase x_votes, 'count={xen:number $response.response_vote_count}'}</a> <xen:else /> {xen:phrase x_votes, 'count={xen:number $response.response_vote_count}'} </xen:if> </div> <div class="percentage"> <xen:if is="{$poll.voter_count}"> {xen:number {xen:calc "100 * {$response.response_vote_count} / {$poll.voter_count}"}, 1}% <xen:else /> {xen:number 0, 1}% </xen:if> </div> </li> </ol> </li> </xen:foreach> </ol>
It will look like so:
So on a side note you need to make sure that you include the <ol class=”pollOptions”> at the top this declares the class and without it your code will break.
So click Save All Changes. How do we test this? Go make a poll and don’t vote in it and you will see this:
So as you can see you have the number of votes and if someone voted you would see who.
There you have it! If you have any questions please feel free to ask away!
Looking for quality XenForo hosting? Check out Arvixe Web Solutions