Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.2k views
in Q2A Core by

I was wanting to integrate the fb like button for each question on my website. http://blankanswer.com/

Thanks.. in advance. also, any suggestions for improvements are welcome!

by
Can you explain how you did this?

2 Answers

+1 vote
by

Looks like you already did, it's on the toolbar at the bottom. But another method is a sharing tool like AddThis.

+2 votes
by

This is my own solution:

- First you get code from Addthis.

- Then go to qa-app-format.php and search for:

if ($microformats)
                    $fields['title']='<SPAN CLASS="entry-title">'.$fields['title'];

replace it by code below:

if ($microformats)
                    $fields['title']='<SPAN CLASS="entry-title">'.$fields['title'].'</SPAN><br/>'.
                    '<div class="addthis_toolbox addthis_default_style">'.
                    '<a class="addthis_button_facebook"></a>'.
                    '<a class="addthis_button_twitter"></a>'.
                    '<a class="addthis_button_googlebuzz"></a>'.
                    '<a class="addthis_button_email"></a>'.
                    '<span class="addthis_separator"> </span>'.
                    '<a class="addthis_button_facebook_like"></a>'.                    
                    '<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>';

You can see demo here And if you like my solution, just like my site ;)

 

 

by
It would be much safer to do this in a sidebar widget or with an advanced theme or theme layer plugin, as qa-app-format.php will be overwritten when you upgrade Q2A.

Here's the way I do it with a sidebar widget:


class qa_social_share_widget {
       
  function allow_template($template) {
    return true;
  }
       
  function allow_region($region) {
    return true;
  }
       
  function output_widget($region, $place, $themeobject, $template, $request, &$qa_content)
  {
    ?>
    <!-- AddThis Button BEGIN -->
    <div class="addthis_toolbox addthis_default_style in_<?= $region ?>">
      <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
      <a class="addthis_button_tweet"></a>
    </div>
    <script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
    <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xxxxxxxx"></script>
    <!-- AddThis Button END -->           
    <?
  }
       
};
by
Nice code. However I'm using Q2A 1.3.3 so if you code works with this version or just for 1.4? If so, I will change to safer one.
by
This version will only work with the upcoming 1.4, yes (or the current developer preview if you're in the process of developing your site). I should have been more clear there.

An equivalent approach for 1.3.3 would be to use an advanced theme and override just the piece of code for the area you want to apply it to.

You could do this with your own theme with a qa-theme.php something like this:

<?php

class qa_html_theme extends qa_html_theme_base {

  function page_title() {
    qa_html_theme_base::page_title();
    $this->output("...");
  }
 
}

?>

The AddThis stuff would go where the "..." is.

This theme file would leave everything else unchanged, but override the page title to place the AddThis code immediately below the header.

Alternatively, considering AddThis requires javascript anyway, you could consider using something like the jQuery AddThis plugin?

http://plugins.jquery.com/project/AddThis

You could use jQuery to insert a div element after the entry-title span or the h1, then apply the jQuery plugin to that?
by
Hi Tenkana, does the code that you suggest above (changing the qa-app-format.php) still works in 1.4. I tried it but it didn't work. I don't have a php knowledge so I am scared to try to implement dofmika suggestion using advance theme.
by
My suggest above works just fine in QAv1.3 but 'm not sure for QAv1.4. In version 1.4 I dont modify original code any more just do it all in advanced theme.

For AddThis stuff you should follow dofmike instruction or put this stuff below into your advance theme. Sure it works.

function q_view_main($q_view){
            $this->output('<DIV CLASS="qa-q-view-main">');
            /*-- Tenkana-QA Addon: Socialstream buttons --*/
            $this->output('<div class="addthis_toolbox addthis_default_style">'.
                    '<a class="addthis_button_facebook"></a>'.
                    '<a class="addthis_button_twitter"></a>'.
                    '<a class="addthis_button_googlebuzz"></a>'.
                    '<a class="addthis_button_email"></a>'.
                    '<span class="addthis_separator"> </span>'.
                    '<a class="addthis_button_facebook_like"></a>'.                   
                    '<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script></div>');
            /*-- ------------------------------------- --*/
            $this->q_view_content($q_view);
            $this->q_view_follows($q_view);
            $this->post_tags($q_view, 'qa-q-view');
            $this->post_avatar($q_view, 'qa-q-view');
            $this->post_meta($q_view, 'qa-q-view');
            $this->q_view_buttons($q_view);
            $this->c_list(@$q_view['c_list'], 'qa-q-view');
            $this->form(@$q_view['a_form']);
            $this->c_list(@$q_view['a_form']['c_list'], 'qa-a-item');
            $this->form(@$q_view['c_form']);
           
            $this->output('</DIV> <!-- END qa-q-view-main -->');
        }
by
edited by
@tenkana But how can i add above of the title? because in your tutorial is below the title.

Thanks
by
hey thank you so much. I used your code except changed it a little because yours is outdated.
...