Show who has voted and how many votes before voting in Xenforo

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>

We are going to replace it with another code which is the following:

        <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>
            <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>
            <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>
            <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}'}
            <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}%

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

Tags: , , , , , , , , , , , , , , | Posted under XenForo | RSS 2.0

Author Spotlight

Keith Pottratz

Hello My Name is Keith Pottratz. I have been working with computers for over a decade. It's my personal hobby something that I love and enjoy doing. I went to school for Computer Science, and have spent many years self teaching my self various things. I have ton's of experience in HTML,CSS, PHPBB,CPanel,CMS software, blogging software and various other systems and enviroments. My favorite thing to do though is backend developing. I find it to be a growing and ever evolving beast and I love learning about it. I look forward to giving as much knowledge as I can and help.

Leave a Reply

Your email address will not be published. Required fields are marked *