Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

ideas on google +1 to replace votes

+3 votes
506 views
asked Jun 20, 2011 in Q2A Core by mshelton
I am trying to implement a google +1 button to replace the voting system in Q2A. I believe I have correctly implemented the buttons but I am unsure of how to fetch the question URL and add it as the href element in the <g:plusone></g:plusone> tag.

I am trying to use qa-theme as follows:

function voting_inner_html($post)
        {
            $this->output('<g:plusone HREF=?></g:plusone>');
    
        }
 

I have tried several different combinations to figure out how to get the full url for each question but haven't had any luck. Any suggestions? Thanks.
commented Jun 20, 2011 by mshelton
changing back to my default theme for now so you won't see the +1 implementation. Still appreciate any suggestions.

1 Answer

+2 votes
answered Jun 21, 2011 by Scott

Ha, that's an interesting way to go, if a little sneaky! Not sure what your HREF thing is for, but the code for the +1 button is this:

<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone size="tall"></g:plusone>

You can move the script tag to anywhere on the page - recommended to be before the closing </body> tag, so maybe in Q2A's footer() function. Something like this should work:

function voting_inner_html($post)
{
    $this->output('<g:plusone size="tall"></g:plusone>');
}

function footer()
{
    qa_html_theme_base::footer();
    $this->output('<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>');    
}

 
commented Jun 22, 2011 by Scott
OK I see - assumed you just had one button on each question page, not on the list of questions. The problem with your code above is that you put the variable inside a string. Try this:

$this->output('<g:plusone href="'.$question['url'].'"></g:plusone>');
commented Jun 22, 2011 by mshelton
Just wanted you and anyone else who is interested I figured it out.

www.mathhomeworkanswers.org

I had to incorporate the buttons into the following function:

function q_item_title($question)
        {
           
            $this->output(
                '<DIV CLASS="qa-q-item-title-b">',
                '<g:plusone HREF="http://mathhomeworkanswers.org/'.$question['url'].'"></g:plusone>',
                '</DIV>'
            );
               
        $this->output(
                '<DIV CLASS="qa-q-item-title">',
                '<A HREF="'.$question['url'].'">'.$question['title'].'</A>',
                '</DIV>'
            );
        }

I think this was because the title links are part of a loop on most of those pages. In order to get the url variable to work correctly I had to be inside of the loop.  There may be another way to do this. . .just what I came up with and it seems to work.
...